gpt4 book ai didi

javascript - jQuery 表单提交未被调用

转载 作者:行者123 更新时间:2023-12-02 13:47:05 27 4
gpt4 key购买 nike

我有这段代码,通过单击“练习按钮”将 html 元素添加到 div 元素。但是,当我单击表单上的提交按钮时,它不会调用“选定的练习选项”。然而,我在网站上的另一个表格称为“选定的练习选项”。该代码没有调用“选定练习选项”的 jQuery 事件。 jQuery 代码和 html 代码没有错误。这是 jQuery 的错误吗?

 /* Pratice Button Clicked Event */
- 35 $("#ob-practice").click(function(){
2 36 $("#newComboDiv").css("display","none");
2 37 $("#practiceComboDiv").css("display","inline-block");
2 38 var data = JSON.parse(localStorage.getItem('c'));
2 39 var text = "<form id='comboselect' action='#'> <select name='option-name'>";
- 40 for (var i in data){
3 41 var m = data[i];
3 42 text += "<option> " + m.name + "</option>";
3 43 }
2 44 text += "</select>"
2 45 text += "<button type='submit' value='submit'> Submit </button> </form>"
2 46 $("#combo-menu").html(text);
2 47 });
| 48 /*Selected Practice Option */
- 49 $("form").on("submit",function(e){
2 50 e.preventDefault();
2 51 var data = $('#comboselect').serializeArray();
2 52 alert("test");
2 53
2 54 });

最佳答案

click上上$("#ob-practice")<form id='comboselect'>$("#combo-menu") 中动态创建为子项元素。

尝试来自 $("#combo-menu") 的“委托(delegate)”其子代的标签名称为 form :

$("#combo-menu").on("submit","form",function(e){
e.preventDefault();
var data = $('#comboselect').serializeArray();
alert("test");
});

关于javascript - jQuery 表单提交未被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41309104/

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