Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/73.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变量不起作用_Jquery - Fatal编程技术网

悬停中的Jquery变量不起作用

悬停中的Jquery变量不起作用,jquery,Jquery,嘿,在那里,在代码上工作,并且有点让它工作。 现在请告诉我怎么了。 在hover.photo上,我使用.photo中链接的rel值创建一个变量performer 我想在鼠标离开时使用这个变量。 它现在起作用了,有什么想法吗 $(".photo").hoverIntent(function() { var performer = $(".photo").attr("rel"); $(this).html('<object classid="clsid:D27CDB

嘿,在那里,在代码上工作,并且有点让它工作。 现在请告诉我怎么了。 在hover.photo上,我使用.photo中链接的rel值创建一个变量performer

我想在鼠标离开时使用这个变量。 它现在起作用了,有什么想法吗

$(".photo").hoverIntent(function() {

      var performer = $(".photo").attr("rel");

      $(this).html('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,24,0" width="250" height="250"><param name="movie" value="http://static.awempire.com/flash/live_feeds/live_feed.swf" /><param name="quality" value="high" /><param name="wmode" value="transparent" /><param name="flashvars" value="appletroot=http://static.awempire.com/flash/live_feeds/&appletskin=template8/template01.swf&appletcol=900000&psid=ddany23&campaign_id=20520&pstour=t1&psprogram=REVS&site=jsm&flags=137438953473,137438953504,1,32&lp_lang=auto" /><embed src="http://static.awempire.com/flash/live_feeds/live_feed.swf" width="250" height="250" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" wmode="transparent" flashvars="appletroot=http://static.awempire.com/flash/live_feeds/&appletskin=template8/template01.swf&appletcol=900000&psid=ddany23&campaign_id=20520&pstour=t1&psprogram=REVS&site=jsm&flags=137438953473,137438953504,1,32&lp_lang=auto"></embed></object>');
    }, function() {
      $(this).html(''+performer+'');
    });
$(“.photo”).hoverIntent(函数(){
var performer=$(“.photo”).attr(“rel”);
$(this.html(“”);
},函数(){
$(this.html(“”+performer+“”);
});

您创建的第二个匿名函数无法看到performer变量,它不在作用域链中。你必须像这样把它放在外面:

$('.photo').each(function() { // All of the .photo divs....
    var performer = $(this).attr("rel");
    $(this).hoverIntent(function() {
        // The second function can't see in here
        $(this).html('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,24,0" width="250" height="250"><param name="movie" value="http://static.awempire.com/flash/live_feeds/live_feed.swf" /><param name="quality" value="high" /><param name="wmode" value="transparent" /><param name="flashvars" value="appletroot=http://static.awempire.com/flash/live_feeds/&appletskin=template8/template01.swf&appletcol=900000&psid=ddany23&campaign_id=20520&pstour=t1&psprogram=REVS&site=jsm&flags=137438953473,137438953504,1,32&lp_lang=auto" /><embed src="http://static.awempire.com/flash/live_feeds/live_feed.swf" width="250" height="250" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" wmode="transparent" flashvars="appletroot=http://static.awempire.com/flash/live_feeds/&appletskin=template8/template01.swf&appletcol=900000&psid=ddany23&campaign_id=20520&pstour=t1&psprogram=REVS&site=jsm&flags=137438953473,137438953504,1,32&lp_lang=auto"></embed></object>');
    }, function() {
        $(this).html(''+performer+'');
    });
});
$('.photo')。每个(函数(){//所有的.photo div。。。。
var performer=$(this.attr(“rel”);
$(this.hoverIntent(function()){
//第二个函数在这里看不见
$(this.html(“”);
},函数(){
$(this.html(“”+performer+“”);
});
});
如果您不知道为什么,我建议您学习更多关于javascript中闭包的知识


编辑 对不起,我不知道有重复的

使用each遍历each并为each.photo创建一个变量,然后创建的匿名函数可以引用该变量


编辑 此外,我不明白为什么您不直接使用原始代码并执行以下操作:

$(this).hoverIntent(function() {
    $(this).html('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,24,0" width="250" height="250"><param name="movie" value="http://static.awempire.com/flash/live_feeds/live_feed.swf" /><param name="quality" value="high" /><param name="wmode" value="transparent" /><param name="flashvars" value="appletroot=http://static.awempire.com/flash/live_feeds/&appletskin=template8/template01.swf&appletcol=900000&psid=ddany23&campaign_id=20520&pstour=t1&psprogram=REVS&site=jsm&flags=137438953473,137438953504,1,32&lp_lang=auto" /><embed src="http://static.awempire.com/flash/live_feeds/live_feed.swf" width="250" height="250" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" wmode="transparent" flashvars="appletroot=http://static.awempire.com/flash/live_feeds/&appletskin=template8/template01.swf&appletcol=900000&psid=ddany23&campaign_id=20520&pstour=t1&psprogram=REVS&site=jsm&flags=137438953473,137438953504,1,32&lp_lang=auto"></embed></object>');
}, function() {
    $(this).html('' + $(this).attr("rel") + '');
});
$(this).hoverIntent(function(){
$(this.html(“”);
},函数(){
$(this.html(“”+$(this.attr(“rel”)+“”);
});

您创建的第二个匿名函数无法看到performer变量,它不在作用域链中。你必须像这样把它放在外面:

$('.photo').each(function() { // All of the .photo divs....
    var performer = $(this).attr("rel");
    $(this).hoverIntent(function() {
        // The second function can't see in here
        $(this).html('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,24,0" width="250" height="250"><param name="movie" value="http://static.awempire.com/flash/live_feeds/live_feed.swf" /><param name="quality" value="high" /><param name="wmode" value="transparent" /><param name="flashvars" value="appletroot=http://static.awempire.com/flash/live_feeds/&appletskin=template8/template01.swf&appletcol=900000&psid=ddany23&campaign_id=20520&pstour=t1&psprogram=REVS&site=jsm&flags=137438953473,137438953504,1,32&lp_lang=auto" /><embed src="http://static.awempire.com/flash/live_feeds/live_feed.swf" width="250" height="250" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" wmode="transparent" flashvars="appletroot=http://static.awempire.com/flash/live_feeds/&appletskin=template8/template01.swf&appletcol=900000&psid=ddany23&campaign_id=20520&pstour=t1&psprogram=REVS&site=jsm&flags=137438953473,137438953504,1,32&lp_lang=auto"></embed></object>');
    }, function() {
        $(this).html(''+performer+'');
    });
});
$('.photo')。每个(函数(){//所有的.photo div。。。。
var performer=$(this.attr(“rel”);
$(this.hoverIntent(function()){
//第二个函数在这里看不见
$(this.html(“”);
},函数(){
$(this.html(“”+performer+“”);
});
});
如果您不知道为什么,我建议您学习更多关于javascript中闭包的知识


编辑 对不起,我不知道有重复的

使用each遍历each并为each.photo创建一个变量,然后创建的匿名函数可以引用该变量


编辑 此外,我不明白为什么您不直接使用原始代码并执行以下操作:

$(this).hoverIntent(function() {
    $(this).html('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,24,0" width="250" height="250"><param name="movie" value="http://static.awempire.com/flash/live_feeds/live_feed.swf" /><param name="quality" value="high" /><param name="wmode" value="transparent" /><param name="flashvars" value="appletroot=http://static.awempire.com/flash/live_feeds/&appletskin=template8/template01.swf&appletcol=900000&psid=ddany23&campaign_id=20520&pstour=t1&psprogram=REVS&site=jsm&flags=137438953473,137438953504,1,32&lp_lang=auto" /><embed src="http://static.awempire.com/flash/live_feeds/live_feed.swf" width="250" height="250" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" wmode="transparent" flashvars="appletroot=http://static.awempire.com/flash/live_feeds/&appletskin=template8/template01.swf&appletcol=900000&psid=ddany23&campaign_id=20520&pstour=t1&psprogram=REVS&site=jsm&flags=137438953473,137438953504,1,32&lp_lang=auto"></embed></object>');
}, function() {
    $(this).html('' + $(this).attr("rel") + '');
});
$(this).hoverIntent(function(){
$(this.html(“”);
},函数(){
$(this.html(“”+$(this.attr(“rel”)+“”);
});

在第一个函数之外启动performer,使其成为全局变量,如下所示:

var performer = 1;
$(".photo").hoverIntent(function() {

      performer = $(".photo").attr("rel");

      $(this).html('stuff....');
    }, function() {
      $(this).html(''+performer+'');
    });

通过在第一个函数之外启动performer,使其成为全局变量,如下所示:

var performer = 1;
$(".photo").hoverIntent(function() {

      performer = $(".photo").attr("rel");

      $(this).html('stuff....');
    }, function() {
      $(this).html(''+performer+'');
    });

是的,但现在当我悬停在照片外时,它显示“未定义”。我有10张照片。请让我更好地解释。。。每一种方法,我都很确定它不会起作用。我有10张照片和10张不同的照片。当我在任何一个上面悬停时,它会播放闪光灯。当我悬停在外时,我希望图像与此相关。照片分区是shownYes,但现在当我悬停在照片外时,它显示“未定义”。我有10个。照片分区请让我更好地解释。。。每一种方法,我都很确定它不会起作用。我有10张照片和10张不同的照片。当我在任何一个上面悬停时,它会播放闪光灯。当我悬停在外时,我希望显示与该.photo div相关的图像