如果多个HTML元素是不同的元素,它们是否具有相同的ID?这样的情况有效吗?:div#foospan#fooa#foo
4 回答
HUH函数
TA贡献1836条经验 获得超4个赞
慕运维8079593
TA贡献1876条经验 获得超5个赞
<button id="myid" data-mydata="this is button 1">button 1</button><button id="myid" data-mydata="this is button 2">button 2</button> <button id="myid" data-mydata="this is button 3">button 3</button>
jQuery
myid
$(document).ready(function (){ $("#myid").click(function () { var buttonData = $(this).data("mydata"); // Call interesting function... interestingFunction(); $('form').trigger('submit'); });});
IDs
HTML
<button id="button1" class="mybtn" data-mydata="this is button 1">button 1</button><button id="button2" class="mybtn" data-mydata="this is button 2">button 2</button><button id="button3" class="mybtn" data-mydata="this is button 3">button 3</button>
CSS
$(document).ready(function (){ $(".mybtn").click(function () { var buttonData = $(this).data("mydata"); // Call interesting function... interstingFunction(); $('form').trigger('submit'); });});
添加回答
举报
0/150
提交
取消