jquery - 当选中单选按钮时将属性设置为必需

标签 jquery

我试图将一个选择框设置为“必需”,但只有当我的单选按钮被选中时,下面是我所拥有的,但似乎不起作用。

  <input type="radio" name="radio" id="radio" />

  <select name="selectbox" id="selectbox">
  <option value="1"> 1 </option>
  <option value="2"> 2 </option>
  <option value="3"> 3 </option>
  </select>

和代码

  function radiocheck(){
      if($('#radio').is(':checked')){
      $('#selectbox').prop('required',true);
      }}

最佳答案

试试这个:

$(document).ready(function(){
    $('#radio').change(function(e){
        if($('#radio').is(':checked')){
            $('#selectbox').prop('required',true);
        }
    });
});

See it in action here

关于jquery - 当选中单选按钮时将属性设置为必需,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30199811/

相关文章:

javascript - getImageURI() 不适用于 orgchart by google

jquery - CSS/Jquery 固定标题 + 更改

jquery - 同时使用jinja和jquery.tmpl.js时TemplateSyntaxError : expected token 'end of print statement' ,得到 'news'

jquery - 返回嵌套元素的索引

aoCoulumn 中的 jquery 数据表 img

jQuery-Seat-Chart 重新映射现有座位

jQuery水平动画而不是垂直动画

javascript - jQuery/js for循环,添加具有不同结束编号的变量来分隔div

jquery - 访问 jQuery 自动完成对象

javascript - 当输入框位于模式内时,HTML ajax 标签不显示