admin管理员组文章数量:1321070
I am adding a slider dynamically on a page using a string like the one below:
"<input type=\"range\" name=\"aName\" min=\"1\" max=\"9\"/>";
Then, after I append it to the page using plain javascript I can delegate using the following code:
$('input[name=aName]').on('change', function () { alert(this.value)});
and indeed when the value changes, I receive the alert with the correct value. However, if I delegate like this:
$('input[name=aName]').on('change', handleChange);
and define the function later on like this:
function handleChange () {
var theValue = $('input[name=aName]').value;
alert("value: " + theValue);
}
I receive the alert with the message "value: undefined". Why is this thing happening?
I am adding a slider dynamically on a page using a string like the one below:
"<input type=\"range\" name=\"aName\" min=\"1\" max=\"9\"/>";
Then, after I append it to the page using plain javascript I can delegate using the following code:
$('input[name=aName]').on('change', function () { alert(this.value)});
and indeed when the value changes, I receive the alert with the correct value. However, if I delegate like this:
$('input[name=aName]').on('change', handleChange);
and define the function later on like this:
function handleChange () {
var theValue = $('input[name=aName]').value;
alert("value: " + theValue);
}
I receive the alert with the message "value: undefined". Why is this thing happening?
Share Improve this question asked Oct 31, 2013 at 20:52 MightyMouseMightyMouse 13.9k8 gold badges35 silver badges45 bronze badges 2-
what is
handleChange
? there is onlyhandleRQTSliderChange
– Venkata Krishna Commented Oct 31, 2013 at 20:53 - That was a mistake on my side. Clearly it is handleChange in both cases. I have edited the post. – MightyMouse Commented Oct 31, 2013 at 20:54
1 Answer
Reset to default 4This is wrong $('input[name=aName]').value
. I think you're mixing javascript & jquery.
For getting the value, use like this.
$('input[name=aName]').val()
本文标签: javascriptGetting value from a range input (slider)Stack Overflow
版权声明:本文标题:javascript - Getting value from a range input (slider) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742090711a2420250.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论