简体   繁体   English

更改时的jQuery无法在输入字段类型范围上使用

[英]Jquery on change not working on input field type range

I use a input with type range and try to refresh the innerHTML of an output field with id output with the selected value, each time when the value changes. 我使用类型rangeinput ,并尝试在每次值更改时刷新具有选定值的id output的输出字段的innerHTML。

I solved it like this: 我这样解决了:

 function regler() { document.getElementById("output").innerHTML = document.getElementById("regler").value; } 
 <input id="regler" value="0" type="range" onchange="regler()"> <p id="output"></p> 

This works. 这可行。 But if i try it with Jquery then nothing happens: 但是如果我用Jquery尝试,那么什么也不会发生:

 $("#regler").on ( "change", function(event) { document.getElementById("output").innerHTML = document.getElementById("regler").value; } ); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input id="regler" value="0" type="range"> <p id="output"></p> 

What am i doing wrong? 我究竟做错了什么?

EDIT : I just noticed that the code runs well on SO but not on my local webserver? 编辑 :我只是注意到代码可以在SO上很好地运行,但不能在我的本地Web服务器上运行?

EDIT2 : Why is my range field looking like this (Tested with Chrome and Firefox): EDIT2 :为什么我的范围字段看起来像这样(已通过Chrome和Firefox测试):

在此处输入图片说明

Instead like this: 而是这样:

在此处输入图片说明

I figured out the problem. 我解决了这个问题。 The problem is that i include jquery.mobile-1.4.5.min.js after my normal jquery-2.2.3.min.js script. 问题是我在普通的jquery-2.2.3.min.js脚本之后包含了jquery.mobile-1.4.5.min.js

After i changed the order, it works. 我更改订单后,它可以工作。 Sorry for not mentioning that i include jquery.mobile , i did not knew that this file has something to do with the problem. 对不起,我没有提到我包括jquery.mobile ,我不知道该文件与问题有关。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM