Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/77.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 根据JQueryUI滑块的值选中单选按钮_Javascript_Jquery_Jquery Ui_Slider_Radio Button - Fatal编程技术网

Javascript 根据JQueryUI滑块的值选中单选按钮

Javascript 根据JQueryUI滑块的值选中单选按钮,javascript,jquery,jquery-ui,slider,radio-button,Javascript,Jquery,Jquery Ui,Slider,Radio Button,我在一个页面上有几个不同行为的滑块。其中一个滑块与单选按钮集关联。选中单选按钮时,滑块的值应更新。这是有效的。但是,我无法使反转工作-当手动移动滑块时,应检查相应值的单选按钮 以下是我的JS: //When radio buttons are changed, update slider - this works $('[name="[smoker]"]').change(function () { var value = this.value; $('#smoker'

我在一个页面上有几个不同行为的滑块。其中一个滑块与单选按钮集关联。选中单选按钮时,滑块的值应更新。这是有效的。但是,我无法使反转工作-当手动移动滑块时,应检查相应值的单选按钮

以下是我的JS:

//When radio buttons are changed, update slider - this works
$('[name="[smoker]"]').change(function () {
      var value = this.value;
      $('#smoker').slider("value", value);
});

//When slider is changed, update radio buttons - this doesn't work. The alert event never fires.
$('#smoker').change(function () {
    alert(value)
     ($('[name="[smoker]"]').attr("value", value)).attr("checked",true);
});
这是我的分数:

 <div class="slider" id="smoker" data-begin="0" data-end="4"></div>
 <input type="radio" class="smoker_radio" name="[smoker]" value="0" id="smoker[1]">
<input type="radio" class="smoker_radio" name="[smoker]" value="1" id="smoker[2]">
<input type="radio" class="smoker_radio" name="[smoker]" value="2" id="smoker[3]">
<input type="radio" class="smoker_radio" name="[smoker]" value="3" id="smoker[4]">
<input type="radio" class="smoker_radio" name="[smoker]" value="4" id="smoker[5]">

试试看

演示:

试试看

演示:

试试看

演示:

试试看

演示:

您可以执行以下操作:

slide: function (event, ui) {              
   $(".smoker_radio[value='"+ui.value+"']").attr("checked", true);
   //or better use .prop()
   $(".smoker_radio[value='"+ui.value+"']").prop("checked", true);
}
更新了

您可以执行以下操作:

slide: function (event, ui) {              
   $(".smoker_radio[value='"+ui.value+"']").attr("checked", true);
   //or better use .prop()
   $(".smoker_radio[value='"+ui.value+"']").prop("checked", true);
}
更新了

您可以执行以下操作:

slide: function (event, ui) {              
   $(".smoker_radio[value='"+ui.value+"']").attr("checked", true);
   //or better use .prop()
   $(".smoker_radio[value='"+ui.value+"']").prop("checked", true);
}
更新了

您可以执行以下操作:

slide: function (event, ui) {              
   $(".smoker_radio[value='"+ui.value+"']").attr("checked", true);
   //or better use .prop()
   $(".smoker_radio[value='"+ui.value+"']").prop("checked", true);
}
更新