Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JQuery-动态Img Src Attr更改_Jquery_Jquery Ui - Fatal编程技术网

JQuery-动态Img Src Attr更改

JQuery-动态Img Src Attr更改,jquery,jquery-ui,Jquery,Jquery Ui,有人能解释一下,这个代码有什么问题吗。在Web浏览器中打开html后,图像不会在间隔时间内动态更改 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Blinking Text</title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery

有人能解释一下,这个代码有什么问题吗。在Web浏览器中打开html后,图像不会在间隔时间内动态更改

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Blinking Text</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
$(function() {
    var x;
        setInterval(function() {
                if(x == 0) {
                        $('blinking').attr('src', "http://www.example.com/images/banner1.png");         
                        x = 1;
                } else  {
                    if(x = 1) {
                        $('blinking').attr('src', "http://www.example.com/images/banner2.png");             
                        x = 0;
                    }
                }
        }, 750);
});
</script>
</head>
<body>  
    <div class="blinking"><img src="http://www.example.com/images/banner1.png"></img></div>
</table>    
</body>
</html>

闪烁文本
$(函数(){
var x;
setInterval(函数(){
如果(x==0){
$('blinking').attr('src',”http://www.example.com/images/banner1.png");         
x=1;
}否则{
如果(x=1){
$('blinking').attr('src',”http://www.example.com/images/banner2.png");             
x=0;
}
}
}, 750);
});
  • 提前谢谢

    • 您忘记为图像添加
      类选择器

      $('.blinking img')
      

      $('.blinking img')
      表示您正在选择
      图像
      ,其
      父项
      闪烁div

      问题在于jQuery选择器
      $('blinking')

      如果您是按类选择,则应为
      $('.blinking img')
      。注意

      $('div.blinking img');
      
      $('div.blinking')
      -->
      div
      带类
      blinking

      $(“div.blinking img”)-->其父级为div且类闪烁的图像。

      此$(“闪烁”)对jQuery没有任何意义,它认为您正在查看ro和元素闪烁如果您正在选择类,则需要指定其前缀选择器示例:

      //CLASS
      $(".blinking")
      //ID
      $("#blinking")
      
      我建议你读书