有没有“白痴证明”?如何重新启用表单上的所有字段(无论状态如何)? [英] Is there an "Idiot proof" way to re-enable all fields (regardless of there state) on a form?

查看:98
本文介绍了有没有“白痴证明”?如何重新启用表单上的所有字段(无论状态如何)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是,我有JavaScript,启用/禁用一些表单域,我已默认禁用,用户不需要发送到我的业务,​​但可以启用它们,如果他们需要与复选框。不过,我显然有一个表单提供者,对于禁用的字段非常有帮助。基本上,访问者将选择复选框来启用他们需要输入的某些字段,或选择。



我可以创建一个复选框将取消所有启用或禁用状态的字段,而不管其当前状态如何,以便所有字段都被提交?



我需要这种功能的另一个原因是因为客户端收到自动回复电子邮件,并且当这些字段被禁用时,如果该字段在提交表单之前被禁用,他们会看到%FeildName%。只是因为数据在表单上提交时从未存在过,显然是因为它处于禁用状态。



如果可以做什么,它是否可以输入到我的现有JavaScript代码?我已经有了一个表单验证脚本,我使用的是javascript。



我并不是很擅长JavaScript,从来没有真正使用过jQuery,也没有有智慧跟随jQuery,所以任何帮助将不胜感激。



我的代码可以在这个页面上看到,只需查看源代码。
http://www.gbjimaging.net/order/form/complete /audio.htm



在表单最底部的复选框中,在提交和重置按钮之前,我想执行此功能,以便所有信息都会保证提交。再次感谢您的预期帮助,我们将非常感激。

解决方案

以下示例是确保您当前表单的所有字段都已重新启用。所有包含输入,select,textarea 复选框标签的元素将在您点击一个按钮时启用: $('input,select')。each(function(){
if($(this).attr('disabled')){
$(this).removeAttr( 'disabled');
}
});
});
});



在线示例



您需要使用jQuery并将它添加到您的页面,方法是将以下内容粘贴到您的页面头部:

 < script src =http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js >< /脚本> 

在这个例子中,Google CDN正在使用中。



请阅读更多关于 jQuery Usage


My problem is that I have javascript that enables/disables some form fields that I have disabled by default that the user doesn't need to send to my business, but can enable them if they need to with a checkbox. However, I obviously have a form provider that is quite finnicky about disabled fields. Basically, the visitor will select checkboxes that will enable certain fields that they need to enter, or choose to.

What I'm curious about, can I create a checkbox that will undo all the fields enabled or disabled state to just enabled, regardless of it's current state, so that all fields get submitted?

Another reason I need this kind of function is because the client receives an autoresponce e-mail, and when the fields are disabled they see %FeildName% if the field was disabled before submitting the form. simply because the field never existed when the data was submitted on the form, obviously because of it's disabled state.

If something can be done, can it be entered in my existing javascript code? I already have a Form Validation script, that I used with javascript.

I'm not exactly great at javascript, and never really even played with jQuery before, nor do I have the intellect to follow jQuery, so any help would be appreciated.

My code can be seen on this page, just view the source. http://www.gbjimaging.net/order/form/complete/audio.htm

The checkbox at the very bottom of the form, before the submit and reset buttons I'd like to perform this function, so that all information is garenteed to be submitted. Again, thanks for your anticipated help, and it really will be appreciated.

解决方案

The following example is the way to make sure that all fields of your current form were re-enabled. All of the elements with input, select, textarea and checkbox tags will become enabled as you click a button:

$(document).ready(function() {
  $('#switcher').click(function() {
    $('input, select').each(function() {
        if ($(this).attr('disabled')) {
            $(this).removeAttr('disabled');
        }
    });
  });
});

Online example

You need to use jQuery and add it to your page by pasting the following to your page's head:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

In this example Google CDN is being used.

Please read more about jQuery Install and jQuery Usage.

这篇关于有没有“白痴证明”?如何重新启用表单上的所有字段(无论状态如何)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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