addClass 不起作用,无法定义(这个)
这是我的 javascript:
$(function() {
$(".image2").click(function() {var image = $(this).attr("rel");
$('#image2').hide();
$('#image2').fadeIn('slow');
$('#image2').html('<embed height="253" width="440" wmode="transparent" src="' + image + '"></embed>');
return false;
});
});
$(document).ready(function() {
$("#thumb2 a").each(function() {
var image = $('#image2 embed').attr('src');alert(image);
if(this.attr('rel') = image )
$(this).addClass("open");
});
});
和我的 html:
<style>
#thumb2 img { border:1px solid #dfdfdf; padding:3px; height:29px; margin-top:5px; opacity:0.3; }
#thumb2 img:hover { border:1px solid #fc7200; opacity:1.0; }
.image2.open { border:1px solid #fc7200; opacity:1.0; }
</style>
<div id="image2"><embed height="253" width="440" wmode="transparent" src="images/kameralar.swf"></embed></div>
<div id="thumb2">
<a href="#" rel="images/kameralar.swf" class="image2" ><img src="images/t1.png" border="0"/></a>
<a href="#" rel="images/standalone.swf" class="image2"><img src="images/t2.png" border="0"/></a>
<a href="#" rel="images/mobil.swf" class="image2"><img src="images/t3.png" border="0"/></a>
<a href="#" rel="images/3b2.swf" class="image2"><img src="images/t4.png" border="0"/></a>
<a href="#" rel="images/canon.swf" class="image2"><img src="images/t5.png" border="0"/></a>
<a href="#" rel="images/indigovision.swf" class="image2"><img src="images/t6.png" border="0"/></a>
</div>
无法将类添加到其 rel 属性与嵌入 src 属性相同的链接...添加了 jquery...请 smb 帮助!
here is my javascript:
$(function() {
$(".image2").click(function() {var image = $(this).attr("rel");
$('#image2').hide();
$('#image2').fadeIn('slow');
$('#image2').html('<embed height="253" width="440" wmode="transparent" src="' + image + '"></embed>');
return false;
});
});
$(document).ready(function() {
$("#thumb2 a").each(function() {
var image = $('#image2 embed').attr('src');alert(image);
if(this.attr('rel') = image )
$(this).addClass("open");
});
});
and my html:
<style>
#thumb2 img { border:1px solid #dfdfdf; padding:3px; height:29px; margin-top:5px; opacity:0.3; }
#thumb2 img:hover { border:1px solid #fc7200; opacity:1.0; }
.image2.open { border:1px solid #fc7200; opacity:1.0; }
</style>
<div id="image2"><embed height="253" width="440" wmode="transparent" src="images/kameralar.swf"></embed></div>
<div id="thumb2">
<a href="#" rel="images/kameralar.swf" class="image2" ><img src="images/t1.png" border="0"/></a>
<a href="#" rel="images/standalone.swf" class="image2"><img src="images/t2.png" border="0"/></a>
<a href="#" rel="images/mobil.swf" class="image2"><img src="images/t3.png" border="0"/></a>
<a href="#" rel="images/3b2.swf" class="image2"><img src="images/t4.png" border="0"/></a>
<a href="#" rel="images/canon.swf" class="image2"><img src="images/t5.png" border="0"/></a>
<a href="#" rel="images/indigovision.swf" class="image2"><img src="images/t6.png" border="0"/></a>
</div>
can't add class to a link whose rel attribute is the same with embed src attribute... jquery is added... pls smb help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题在于
.attr()
不是 DOM 元素上可用的方法,并且=
设置(或尝试)左侧,而不是比较两者。要解决第一个问题,您需要将其包装起来,因此:需要是:
另请注意双
==
用于比较,而不是集合。然而,一个更短、更高效的更好解决方案是:
The problem is that
.attr()
isn't a method available on the DOM element and=
sets (or attempts to) the left side, rather than comparing both. To fix the first, you need to wrap it, so this:needs to be:
Also note the double
==
for a comparison, rather than a set.However, a better solution that both shorter and more efficient would be: