我想在范围滑块上捕捉事件,即使按下按钮并更改值:
$("input").val(1);
http://jsfiddle.net/BaEar/188/
但事件"输入"不按按钮开火。并且"改变"也没有用。
HTML:
<input type="range">
<button>Change</button>
<div id="output"></div>
使用Javascript:
$("input").on("input", function() { //Does not fire on button click :(
$("#output").text($(this).val());
});
$("button").click(function() {
$("input").val(1);
});
有解决方案的人吗?谢谢:))
答案 0 :(得分:2)
首先,将on
处理程序更改为使用change
,如
$("input").on("change", function() {
$("#output").text($(this).val());
});
其次,在点击处理程序中手动触发它,如
$("button").click(function() {
$("input").val(1);
$("input").trigger("change");
});
答案 1 :(得分:1)
我认为com.sun.deploy.net.JARSigningException: Found unsigned entry in resource: http://localhost:8080/<context-root>/client/servlet-api.jar
at com.sun.javaws.security.SigningInfo.getCommonCodeSignersForJar(Unknown Source)
at com.sun.javaws.security.SigningInfo.check(Unknown Source)
at com.sun.javaws.security.JNLPSignedResourcesHelper.checkSignedResourcesHelper(Unknown Source)
at com.sun.javaws.security.JNLPSignedResourcesHelper.checkSignedResources(Unknown Source)
at com.sun.javaws.Launcher.prepareResources(Unknown Source)
at com.sun.javaws.Launcher.prepareAllResources(Unknown Source)
at com.sun.javaws.Launcher.prepareToLaunch(Unknown Source)
at com.sun.javaws.Launcher.prepareToLaunch(Unknown Source)
at com.sun.javaws.Launcher.launch(Unknown Source)
at com.sun.javaws.Main.launchApp(Unknown Source)
at com.sun.javaws.Main.continueInSecureThread(Unknown Source)
at com.sun.javaws.Main.access$000(Unknown Source)
at com.sun.javaws.Main$1.run(Unknown Source)
at java.lang.Thread.run(Thread.java:745)
应更改为$("input").val(1)
。您正在侦听$("input").val(1).trigger('input');
事件,因此在更改应该触发事件的值之后。
jsfiddle - &gt; http://jsfiddle.net/BaEar/191/
答案 2 :(得分:1)
试试这个:
$("input").on("input change", function() {
$("#output").text($(this).val());
});
$("button").click(function() {
$("input").val(1);
$("input").change();
});
http://jsfiddle.net/BaEar/192/
因此,范围滑块通常通过更改值进行更新。如果设置了值,则仅触发AmmarCSE解决方案。