[英]How do you use .js id= multiple times?
I have this code in functions.js 我在functions.js中有这段代码
$("a#example2").fancybox({
'overlayShow' : false,
'transitionIn' : 'elastic',
transitionOut' : 'elastic'
and it works but brings up my only errors while validating as HTML5. 并且可以正常工作,但在验证为HTML5时却出现了我唯一的错误。 This is because I am using six
这是因为我正在使用六个
id="example2"
instances in my gallery and it flags for multiple use. 画廊中的实例,并标记为可多次使用。 When I dug up the templates for this, it had example1, example2 etc. and I just converted all to the one I like.
当我为此挖出模板时,它有example1,example2等,我只是将它们全部转换为自己喜欢的模板。 This is for a gallery on my website at http://www.shaneofalltrades.com .
这是在我的网站http://www.shaneofalltrades.com上的画廊。 Thanks!
谢谢!
id= is intended to be an identifier unique to the whole DOM. id =旨在成为整个DOM唯一的标识符。 class= allows you to group elements by a common identifier.
class =允许您按通用标识符对元素进行分组。
HTML: HTML:
<div class="someClass">Content</div>
CSS: CSS:
.someClass
{
background:transparent;
color:#990000;
}
.someClass div { ... }
jQuery: jQuery的:
$('.someClass').html()
$('.someClass div').html()
You can't. 你不能 You should be using
class="example2"
instead. 您应该改用
class="example2"
。
So your selector will look like: $("a.example2").fancybox({...})
因此您的选择器将如下所示:
$("a.example2").fancybox({...})
Short answer, you don't. 简短的答案,你没有。 That's what classes are for.
那就是上课的目的。
<a class="fancy">....
$('.fancy').fancybox(.....
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.