prop('checked',true)似乎不适用于输入类型无线电

时间:2017-05-26 17:26:24

标签: javascript jquery radio-button

单击按钮时。我显示了一个已检查Active状态的视图。但是代码不起作用。

我无法在这里找到错误。有人可以帮帮我吗? 无论我尝试什么,当我按下按钮点击功能时,单选按钮总是未选中。

我的代码:

$(function(){
  $('#btn').click(function() {
     $('#name').val('');
     $('#active').prop('checked', true);
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="col-md-6 col-sm-6 col-xs-12">
  <input type="radio" class="flat" id="active" name="status" value="true"> Active
  <input type="radio" class="flat" id="inactive" name="status" value="false"> Inactive
</div>

<button type="button" id="btn" class="btn btn-success" >Add</button>

1 个答案:

答案 0 :(得分:0)

我正在使用bootstrap。我从输入类型中删除了class =“flat”。现在它正在工作,但我失去了造型。