如何排除提交HTML表单单选按钮的值? [英] How can I exclude HTML form radio button values from being submitted?

查看:57
本文介绍了如何排除提交HTML表单单选按钮的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只需要通过Web表单向CGI脚本提交一个输入字段值.

I need to submit just one input field value to a cgi script via a web form.

我添加了几个额外的表单控件(复选框和单选按钮),它们可以根据所选状态来操纵输入值.

I've added a couple of extra form controls (a check box and radio buttons) which manipulate the input value depending on the states selected.

提交表单时,还将提交额外的表单字段值,这会破坏cgi脚本(我无权访问).我从复选框中删除了名称"属性,因此未提交它们,但不能对单选按钮执行此操作,因为这会破坏它们的分组.

When the form is submitted, the extra form field values are submitted as well which breaks the cgi script (which I don't have access to). I removed the 'name' attribute from the check boxes so they are not submitted but cannot do this for the radio buttons as it breaks their grouping.

如何防止提交单选按钮值?

How can I prevent radio button values from being submitted?

推荐答案

您可以在 submit 处理程序中向它们添加 disabled 属性,这样可以防止它们被通过jQuery或常规的< form> 提交进行序列化.例如:

You can add a disabled attribute to them in the submit handler, this will prevent them from being serialized, either by jQuery or a normal <form> submission. For example:

$("#myForm").submit(function() {
  $(this).find(":radio, :checkbox").attr("disabled", true);
});

或者您也可以 .serialize() 仅所需的元素,例如:

Or you can .serialize() only the elements you want, for example:

$.post("myPage.cgi", $("#myForm input[type=text]").serialize());

这篇关于如何排除提交HTML表单单选按钮的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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