gpt4 book ai didi

javascript - 使用 .submit() 事件处理程序通过 JQuery 循环表单字段

转载 作者:行者123 更新时间:2023-11-30 23:51:24 24 4
gpt4 key购买 nike

我在使用 jquery 提交表单时遇到了一些问题。我过去用它提交了很多表单,但我只是在想,如何使用事件处理程序 .submit() 来提交表单及其元素而不调用表单 ID。问题是我似乎无法使用 $(this) 链接元素(可以使用 .children() 但我只想通过输入字段使用 .each() )。

这是一个代码片段:

$('.editTimeLink').click(function () {
var id = $(this).attr('rel');
$.get('<?php echo $config["httpRoot"]; ?>/ajax.php?ajax=1&sec=time&a=edit&id=' + id, {}, function (data) {
if (data.returnCode == 1) {
$('#timeBox_' + id).html(data.data);
$('#timeBox_' + id + ' form').bind('submit', function () {
//$(this).$(':input').each(function () {
//$(this).(':input').each(function () {
$(this).each(':input', function () {
alert("adsf");
});

return false;
});
} else if (data.returnCode == 0) {
alert(data.data);
}
}, 'json');

return false;
});

就像您所看到的,我正在尝试以“this”形式提醒每个输入元素的字符串“asdf”。

您可以看到这两行被注释掉了我一直在尝试管理的内容。未注释掉的行也不起作用。我知道如何解决这个问题,例如将表单选择器名称传递给 lambda 函数,但我只是在想是否有更“干净”的方法来做到这一点?

提前致谢。克里斯汀。

最佳答案

.children() 选择直接子级,因此如果您的表单中有表格或其他标记,您将需要使用 .find()

$(this).find(':input').each(function(i){
console.log($(this).val()); //$(this) now contains the current form field in the loop
});

关于javascript - 使用 .submit() 事件处理程序通过 JQuery 循环表单字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1439492/

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