Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 一旦我检查了一个输入类型收音机,如何禁用和启用返回输入类型submit?_Javascript_Jquery_Html_Forms_Radio Button - Fatal编程技术网

Javascript 一旦我检查了一个输入类型收音机,如何禁用和启用返回输入类型submit?

Javascript 一旦我检查了一个输入类型收音机,如何禁用和启用返回输入类型submit?,javascript,jquery,html,forms,radio-button,Javascript,Jquery,Html,Forms,Radio Button,我希望标题能说明一切。 我有一个表单,有很多组输入类型的收音机,我希望输入类型提交按钮被禁用,直到每个组中有一个输入类型的收音机被选中。这个例子只是一组输入型收音机,但显然不起作用。我错过了什么 谢谢 您可以使用此代码获取选定类型 $('#check_id').on('change', '[name=cust_check]', function() { checkValues = $('input[name=cust_check]:checked').map(function()

我希望标题能说明一切。 我有一个表单,有很多组输入类型的收音机,我希望输入类型提交按钮被禁用,直到每个组中有一个输入类型的收音机被选中。这个例子只是一组输入型收音机,但显然不起作用。我错过了什么


谢谢

您可以使用此代码获取选定类型

 $('#check_id').on('change', '[name=cust_check]', function() {
    checkValues = $('input[name=cust_check]:checked').map(function()
    {
        return $(this).attr('value');
    }).get();
});


您发布的代码的问题在于,当页面加载时,您运行脚本,此时,在您的演示中,没有选定的无线电输入。要使该代码正常工作,只需将其包装在收音机
元素的
change
事件的事件处理程序中:

// binds the anonymous function of the on() method to act
// as the event-handler for the 'change' event triggered
// on the <input> elements of type=radio:
$('input[type=radio]').on('change', function() {

  var current = $('input.class_x').filter(':checked');
  var sbmtBtn = document.getElementById('SubmitButton');
  sbmtBtn.disabled = true;

  if (current.length > 0) {
    sbmtBtn.disabled = false;
  } else {
    sbmtBtn.disabled = true;
  }

// fires the 'change' event when the script is
// first run, which sets the disabled property
// of the submit-button appropriately:
}).change();
输入{
显示:块;
保证金:0.5em0;
}
输入[type='submit']:已禁用{
颜色:红色;
}


很抱歉,但我应该说我不太懂javascript。你能编辑我当前的代码,这样我就可以工作了吗?或者至少检查一下有什么问题。谢谢你!好的,这似乎是一条路。问题是在我最初的项目中,我有很多组输入型收音机,你会如何将你的代码改编成这种形式?我看到了你的代码,我更新了你使用错误的类名
。limit_radio1
类在你的html中不可用请查看该类的解决方案。使用相同的类应用,或者类名不同,分别使用jquery中的
调用My bad!你是对的!我用错了类名,对不起,是的。哦,但是代码并没有像我问的那样工作,需要的是输入类型submit被禁用,直到第一个无线组和第二个无线组中的一个被选中。在您的最后一个小提琴中,提交按钮只需选中一个组即可启用。有什么办法吗?对不起,前面的错误!清楚地告诉…当按钮的时间被禁用时..2分组检查或任何单选检查这是一个很好的解释。我能说什么?至少非常感谢!我将仔细研究所有这些笔记。我很高兴在您的最后一个示例中使用了以下语法:if(current.length>0)。。。。。。因为这是我一开始看到的。一个非常有用的答案,真的。
$(document).ready(function () {
var sbmtBtn = document.getElementById('SubmitButton');
sbmtBtn.disabled = true;
$('.class_x').click(function (){
if ($('.class_x').is(':checked')){//if only allow any on of the radio checked
sbmtBtn.disabled= false; 
}
else{
sbmtBtn.disabled = true;
}
})
});
// binds the anonymous function of the on() method to act
// as the event-handler for the 'change' event triggered
// on the <input> elements of type=radio:
$('input[type=radio]').on('change', function() {

  var current = $('input.class_x').filter(':checked');
  var sbmtBtn = document.getElementById('SubmitButton');
  sbmtBtn.disabled = true;

  if (current.length > 0) {
    sbmtBtn.disabled = false;
  } else {
    sbmtBtn.disabled = true;
  }

// fires the 'change' event when the script is
// first run, which sets the disabled property
// of the submit-button appropriately:
}).change();