hob*_*bok 20 html javascript jquery html5
我在表单中有两个按钮,想要检查哪一个被单击.使用radioButtons一切正常:
if($("input[@name='class']:checked").val() == 'A')
Run Code Online (Sandbox Code Playgroud)
简单的提交按钮一切都崩溃了.
谢谢!
小智 45
$('#submit1, #submit2').click(function () {
if (this.id == 'submit1') {
alert('Submit 1 clicked');
}
else if (this.id == 'submit2') {
alert('Submit 2 clicked');
}
});
Run Code Online (Sandbox Code Playgroud)
小智 14
你可以用这个:
$("#id").click(function()
{
$(this).data('clicked', true);
});
Run Code Online (Sandbox Code Playgroud)
现在通过if语句检查它:
if($("#id").data('clicked'))
{
// code here
}
Run Code Online (Sandbox Code Playgroud)
有关更多信息,您可以访问.data()函数上的jQuery网站.
jQuery(':button').click(function () {
if (this.id == 'button1') {
alert('Button 1 was clicked');
}
else if (this.id == 'button2') {
alert('Button 2 was clicked');
}
});
Run Code Online (Sandbox Code Playgroud)
编辑:-这将适用于所有按钮。
$('input[type="button"]').click(function (e) {
if (e.target) {
alert(e.target.id + ' clicked');
}
});
Run Code Online (Sandbox Code Playgroud)
你应该稍微调整一下(例如,使用一个名称而不是一个id来提醒),但这样你就有了更多的通用功能.
| 归档时间: |
|
| 查看次数: |
120394 次 |
| 最近记录: |