Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.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
引导jQuery-将单选按钮设置回默认选中状态_Jquery_Html_Twitter Bootstrap_Radio Button - Fatal编程技术网

引导jQuery-将单选按钮设置回默认选中状态

引导jQuery-将单选按钮设置回默认选中状态,jquery,html,twitter-bootstrap,radio-button,Jquery,Html,Twitter Bootstrap,Radio Button,我在HTML中有以下结构: <div id="RadioGroup" class="btn-group"> <label class="btn btn-default"> <input id="RadioGroupYes" type="radio" class="toggle" value="true" />Yes </label> <label class="btn btn-default active">

我在HTML中有以下结构:

<div id="RadioGroup" class="btn-group">
  <label class="btn btn-default">
    <input id="RadioGroupYes" type="radio" class="toggle" value="true" />Yes
  </label>
  <label class="btn btn-default active">
    <input id="RadioGroupNull" type="radio" class="toggle" checked="checked" value="null" />-
  </label>
  <label class="btn btn-default">
    <input id="RadioGroupNo" type="radio" class="toggle" value="false" />No
  </label>
</div>

您需要向三个按钮添加名称属性,如下所示:

<div id="RadioGroup" class="btn-group">
  <label class="btn btn-default">
    <input id="RadioGroupYes" type="radio" name="myRadios" class="toggle" value="true" />Yes
  </label>
  <label class="btn btn-default active">
    <input id="RadioGroupNull" type="radio" name="myRadios" class="toggle" checked="checked" value="null" />-
  </label>
  <label class="btn btn-default">
    <input id="RadioGroupNo" type="radio" name="myRadios" class="toggle" value="false" />No
  </label>
</div>

<button id="button">OK</button>
<div id="RadioGroup" class="btn-group">
  <label id="RadioGroupYes" class="btn btn-default">
    <input type="radio" class="toggle" value="true" />Yes
  </label>
  <label id="RadioGroupNull" class="btn btn-default active">
    <input type="radio" class="toggle" checked="checked" value="null" />-
  </label>
  <label id="RadioGroupNo" class="btn btn-default">
    <input type="radio" class="toggle" value="false" />No
  </label>
</div>

我已经这样解决了我的问题:

<div id="RadioGroup" class="btn-group">
  <label class="btn btn-default">
    <input id="RadioGroupYes" type="radio" name="myRadios" class="toggle" value="true" />Yes
  </label>
  <label class="btn btn-default active">
    <input id="RadioGroupNull" type="radio" name="myRadios" class="toggle" checked="checked" value="null" />-
  </label>
  <label class="btn btn-default">
    <input id="RadioGroupNo" type="radio" name="myRadios" class="toggle" value="false" />No
  </label>
</div>

<button id="button">OK</button>
<div id="RadioGroup" class="btn-group">
  <label id="RadioGroupYes" class="btn btn-default">
    <input type="radio" class="toggle" value="true" />Yes
  </label>
  <label id="RadioGroupNull" class="btn btn-default active">
    <input type="radio" class="toggle" checked="checked" value="null" />-
  </label>
  <label id="RadioGroupNo" class="btn btn-default">
    <input type="radio" class="toggle" value="false" />No
  </label>
</div>

这一切在表单输入提交上也非常有效。所有测试。

您能发布Jquery代码吗?要向您解释为什么您的代码不能工作,首先我们需要查看您的()代码。您需要显示您的JavaScript/jQuery以便我们为您提供帮助。我做到了:
$('#radiogroup null').prop('checked',true)这只是代码的一行。如果该行位于单击处理程序中,则发布整个处理程序。也就是说,你发布的一行似乎没有任何错误,因此我们需要更多的线索。不确定这是否有什么不同,因为其他所有内容(正如我已经提到的)在点击时都运行良好,没有任何错误,我也没有从这行收到任何错误消息。不幸的是,这也不起作用,仍然没有为我显示任何错误。这就是为什么我们需要更多地查看您的代码。如果你只使用我所拥有的(包括jQuery),它应该可以工作——它在IE、Firefox和Chrome中对我有效。
$('#RadioGroupYes').removeClass('active');
$('#RadioGroupNo').removeClass('active');
$('#RadioGroupNull').addClass('active');