当表格嵌套在表格中时jQuery表单提交 [英] jQuery form submission when form nested in table

查看:103
本文介绍了当表格嵌套在表格中时jQuery表单提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一个原因,表单不会在表内使用jQuery提交,或者我只是做错了什么?我已经在表格外测试了表单提交,然后当我将它包装在一张停止工作的表中时,尽管我添加了一个额外的 parent()来弥补表单移动到代码中的< td> 元素之上。有人可以帮我解决这个问题吗?



HTML

  WITHOUT TABLE 
< select class =select>
< option> Test< / option>
< / select>
< / form>

WITH TABLE
< table>
< tr>
< form action =page.cfmmethod =post>
< td>
< select class =select>
< option> Test< / option>
< / select>
< / td>
< / form>
< / tr>
< / table>

jQuery
< $($)$ $ $(this).parent(form)$ p $ WITHOUT TABLE
$(。select)。 .submit();
}); $()。select()。on(change,function(){
$(this).parent()。parent(form)

with table
$ ).submit();
});


解决方案


为什么表单不会在表内使用jQuery提交,或者我只是做错了什么?


您的HTML无效。使用验证器。表单可以包含整个表格。表格可以完全包含在表格单元格中。表单不能仅包含组成表的某些单元格。



浏览器中的错误更正是将表格放在表格之外,因此尝试提交它会产生意想不到的结果。


Is there a reason why forms won't submit using jQuery inside tables or am I just doing something wrong? I've tested the form submission outside a table, then soon as i wrapped it inside a table it stopped working, even though I added an extra parent() to make up for the form moving above the <td> element within the code. Could anybody be able to help me out with this issue please?

HTML

WITHOUT TABLE
<form action="page.cfm" method="post">
    <select class="select">
        <option>Test</option>
    </select>
</form>

WITH TABLE
<table>
    <tr>
        <form action="page.cfm" method="post">
            <td>
                <select class="select">
                    <option>Test</option>
                </select>
            </td>
        </form>
    </tr>
</table>

jQuery

WITHOUT TABLE
$(".select").on("change", function() {
    $(this).parent("form").submit();
});

WITH TABLE
$(".select").on("change", function() {
    $(this).parent().parent("form").submit();
});

解决方案

Is there a reason why forms won't submit using jQuery inside tables or am I just doing something wrong?

Your HTML is invalid. Use a validator. A form can contain an entire table. A form can be contained entirely in a table cell. A form cannot contain only some cells that make up a table.

Error correction in the browser is putting the form outside the table, so trying to submit it gives unexpected results.

这篇关于当表格嵌套在表格中时jQuery表单提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆