使用Javascript更改文本框中的值 [英] Using Javascript to change a value in a textbox

查看:55
本文介绍了使用Javascript更改文本框中的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<input id="NameAjax" class="ac_input" type="text" value="">

并使用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 ?


推荐答案

你提到Jquery所以我假设你正在使用如果是这样的话试试这个:

You mentioned Jquery so I am going to assume you are using it. If so try this:

$('#NameAjax').attr('value','1')

第一部分 $('#NameAjax')选择输入,第二个 attr('value','1')将value属性设置为1

The first part $('#NameAjax') selects the input and the second attr('value','1') sets the value attribute to 1

这篇关于使用Javascript更改文本框中的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆