gpt4 book ai didi

javascript - 如何在jquery中添加id?

转载 作者:搜寻专家 更新时间:2023-10-31 22:57:39 25 4
gpt4 key购买 nike

我在 jquery 中创建了一个对话框。并且有一个名为“保存”的按钮。我需要向这个保存按钮添加一个 id。我怎样才能在 jquery 中实现这个。这是我的代码

$(function() {
$( "#dialog" ).dialog({

height: 400,
width: 650,
modal: true,
buttons: {

Save: function() {
dialog.dialog( "close" );
}
},
close: function() {
form[ 0 ].reset();
allFields.removeClass( "ui-state-error" );
}

});
});

最佳答案

Save 函数有一个参数 event,它的目标是按钮的 DOM 元素,然后你可以像这样在函数内部设置 id:

Save: function(event) {
$(event.target).attr('id', 'your-id');
}

specification关于 buttons 属性说:

Specifies which buttons should be displayed on the dialog. The context of the callback is the dialog element; if you need access to the button, it is available as the target of the event object.

关于javascript - 如何在jquery中添加id?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38388237/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com