我已经应用了一个具有只读特性的jquery旋钮,如下所示:
<style>
.test{
background: #292929;
margin:50px;
}
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://raw.github.com/aterrien/jQuery-Knob/master/js/jquery.knob.js"></script>
<body>
<input type="text" value="45%" class="dial"><button id="change">Change</button>
</body>
<script>
$(".dial").knob({
readOnly: true,
fgColor: "#00ABC6",
bgColor: "#666666",
thickness: 0.2
});
$(document.body).on('click', 'button#change', function(){
$("input.dial").val('80%');
})
</script>现在,当我点击change按钮时,它只改变了input标签的值,但不能改变旋钮填充区域的百分比。
发布于 2014-09-17 17:45:45
只需在设置输入的值后触发更改事件,如下所示:
$("input.dial").trigger('change');您的代码将如下所示:
<style>
.test{
background: #292929;
margin:50px;
}
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://raw.github.com/aterrien/jQuery-Knob/master/js/jquery.knob.js"></script>
<body>
<input type="text" value="45%" class="dial"><button id="change">Change</button>
</body>
<script>
$(".dial").knob({
readOnly: true,
fgColor: "#00ABC6",
bgColor: "#666666",
thickness: 0.2
});
$(document.body).on('click', 'button#change', function(){
$("input.dial").val('80%');
$("input.dial").trigger('change');
})
</script>发布于 2016-11-21 17:43:54
您可以使用Jquery中的change trigger:
// on line to change
$('.dial').val(27).trigger('change');https://stackoverflow.com/questions/25887224
复制相似问题