Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

按键之图片切换(根据改变src属性值原理) #11

Open
zlluGitHub opened this issue Apr 12, 2018 · 0 comments
Open

按键之图片切换(根据改变src属性值原理) #11

zlluGitHub opened this issue Apr 12, 2018 · 0 comments

Comments

@zlluGitHub
Copy link
Owner

  • setAttribute() 方法创建或改变某个新属性。
   <img id="icon" src="img_1.png"></br>
   <button id="prev">上一张图片</button>
   <button id="next">下一张图片</button>
   <script>
        window.onload=function(){
            //获取需要的标签
            var icon=document.getElementById('icon');
            var icon=document.getElementById('prev');
            var icon=document.getElementById('next');
             //监听按钮的点击
            var max=10 , min=1 , current=1;
            prev.onclick=function(){
                  if(curren===min){
                          curren===max
                     }else{
                          curren--;
                     }
                    icon.setAttribute("src","img_"+curren+".png");
            }
            next.onclick=function(){
                     if(curren===max){
                          curren===min
                     }else{
                          curren++;
                     }
                    icon.setAttribute("src","img_"+curren+".png");
            }
   </script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant