Jquery 有两次相同的div
我在表单上有一个div,但在表单上需要它两次,两个div都独立显示/隐藏。有没有一种方法可以使用jquery插件两次使用相同的div,但使用相同的类名 不需要任何东西,如果按类选择,则具有相同类的两个元素不会冲突:Jquery 有两次相同的div,jquery,html,css,Jquery,Html,Css,我在表单上有一个div,但在表单上需要它两次,两个div都独立显示/隐藏。有没有一种方法可以使用jquery插件两次使用相同的div,但使用相同的类名 不需要任何东西,如果按类选择,则具有相同类的两个元素不会冲突: $('.my-class').bind('click', function () { $(this)...//this always references the actual element on which the event fired }); 如果需要从一个函数中选
$('.my-class').bind('click', function () {
$(this)...//this always references the actual element on which the event fired
});
如果需要从一个函数中选择元素,而该函数未引用正确的元素,则可以使用.eq()
选择适当的索引:
$('.my-class').eq(0).trigger('click');//this will only trigger a click on the first element found, you can use `.eq(1)` for the second, etc.
不需要任何东西,如果按类选择,则具有相同类的两个元素不会冲突:
$('.my-class').bind('click', function () {
$(this)...//this always references the actual element on which the event fired
});
如果需要从一个函数中选择元素,而该函数未引用正确的元素,则可以使用.eq()
选择适当的索引:
$('.my-class').eq(0).trigger('click');//this will only trigger a click on the first element found, you can use `.eq(1)` for the second, etc.
在这里:
现场演示:
因此,您可以克隆您的DIV,并将克隆插入原始DIV之后(或您喜欢的任何位置)。此处:
现场演示:
因此,您可以克隆DIV并将克隆插入原始DIV之后(或任意位置)。多个
元素可能具有相同的类名。另外,
元素可以有多个类名。例如:
<div class="class1 class2">first</div>
<div class="class1 class3">second</div>
$("div.myclass").attr("display", "none");
首先
第二
可以使用class1
名称一起控制,也可以单独使用class2
和class3
名称控制。多个
元素可能具有相同的类名。另外,
元素可以有多个类名。例如:
<div class="class1 class2">first</div>
<div class="class1 class3">second</div>
$("div.myclass").attr("display", "none");
首先
第二
可以一起使用class1
名称进行控制,也可以单独使用class2
和class3
名称进行控制。您可以在HTML中使用任意次数的类。但另一方面,从技术上讲,id只能在HTML页面中使用一次
有许多特定类的选择器示例,例如,$(“div.myclass”)
,然后使用。each()
对所有类进行迭代,例如:
<div class="class1 class2">first</div>
<div class="class1 class3">second</div>
$("div.myclass").attr("display", "none");
您可以在HTML中使用任意次数的类。但另一方面,从技术上讲,id只能在HTML页面中使用一次
有许多特定类的选择器示例,例如,$(“div.myclass”)
,然后使用。each()
对所有类进行迭代,例如:
<div class="class1 class2">first</div>
<div class="class1 class3">second</div>
$("div.myclass").attr("display", "none");
相同的类名,是的。相同的ID,不,因为这是违反规范的。只需使用可见性切换创建两个不同的div。相同的类名,是的。相同的ID,没有,因为这是违反规范的。只需使用可见性切换创建两个不同的div。