javascript 如何使用javascript更改文本框值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15517088/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to change textbox value using javascript
提问by Romi
I am trying to change a textbox value.
am trying following javascript but in both the alerts am getting image only. ie.
$('#FileName').val = "testimage.jpg";
is not changing the text box field value.
我正在尝试更改文本框值。我正在尝试遵循 javascript,但在两个警报中都只获取图像。IE。
$('#FileName').val = "testimage.jpg";
不会更改文本框字段值。
<x:input type="textbox" id="FileName"
width="210px" value=""/>
if ($("#FileName").val() == "image") {
alert($("#FileName").val())
$('#FileName').val = "testimage.jpg";
alert($("#FileName").val())
}
采纳答案by Mikael H?rsj?
val is a method, not a property, so:
val 是一个方法,而不是一个属性,所以:
$('#FileName').val("testimage.jpg";)
回答by Pragnesh Chauhan
you have used jquery
你用过jquery
try $('#FileName').val("testimage.jpg");
尝试 $('#FileName').val("testimage.jpg");
and using javascript document.getElementById('')
并使用 javascript document.getElementById('')
document.getElementById('FileName').value = "testimage.jpg";
回答by Mufaddal
you should try this
你应该试试这个
if ($("#FileName").val() == "image") {
alert($("#FileName").val())
$('#FileName').val("testimage.jpg");
alert($("#FileName").val())
}