Javascript 根据JQueryUI滑块的值选中单选按钮
我在一个页面上有几个不同行为的滑块。其中一个滑块与单选按钮集关联。选中单选按钮时,滑块的值应更新。这是有效的。但是,我无法使反转工作-当手动移动滑块时,应检查相应值的单选按钮 以下是我的JS: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'
//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);
}
更新