admin管理员组文章数量:1394099
<input id="NameAjax" class="ac_input" type="text" value="">
And using jquery:
).click(function(e) {
document.getElementById("NameAjax").value = 1;
}
But after the click the value does not change:
<input id="NameAjax" class="ac_input" type="text" value="">
I am looking for the output to look exactly like:
<input id="NameAjax" class="ac_input" type="text" value="1">
How to fix it ?
<input id="NameAjax" class="ac_input" type="text" value="">
And using jquery:
).click(function(e) {
document.getElementById("NameAjax").value = 1;
}
But after the click the value does not change:
<input id="NameAjax" class="ac_input" type="text" value="">
I am looking for the output to look exactly like:
<input id="NameAjax" class="ac_input" type="text" value="1">
Share Improve this question edited Jan 18, 2012 at 4:08 asked Jan 18, 2012 at 4:01 user1099407user1099407 4How to fix it ?
- What is the click event bound to? Isn't the output correct? – Andrew Whitaker Commented Jan 18, 2012 at 4:04
- Doesn't it have to be a string? – tekknolagi Commented Jan 18, 2012 at 4:07
- 2 Are you using view source to check if it changed? – James Montagne Commented Jan 18, 2012 at 4:08
-
You better not use
attr
to set value. – gdoron Commented Jan 18, 2012 at 4:18
4 Answers
Reset to default 4$("#elementID").on('click', function() {
$("#NameAjax").val('1');
});
You mentioned Jquery so I am going to assume you are using it. If so try this:
$('#NameAjax').attr('value','1')
The first part $('#NameAjax')
selects the input and the second attr('value','1')
sets the value attribute to 1
Use the val
method:
$('#NameAjax').val('1');
Don't use jquery only half the way. And don't use attr
function to set a value.
$("element_idOrclass").click(function() {
$("#NameAjax").attr("value","1");
}
本文标签: jqueryUsing Javascript to change a value in a textboxStack Overflow
版权声明:本文标题:jquery - Using Javascript to change a value in a textbox - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744689000a2619876.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论