HTML Input 不会在更改时更新 value 属性
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7986026/
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
HTML Input is not updating value attribute on change
提问by Spencer Alger
OOPS,Since the "name" field was at the top it was the one I was testing with, and it turned out that was the only one with an issue. Must have something to do with using "name" as the name...
哎呀,由于“名称”字段位于顶部,这是我正在测试的字段,结果证明这是唯一一个有问题的字段。必须与使用“名称”作为名称有关......
For some reason the input tags in my form are not updating the value attribute when they are changed view the actual element (not JavaScript). The data posted to the server is the original value of the "value" attribute, not the text in the textbox.
出于某种原因,我的表单中的输入标签在更改视图实际元素(不是 JavaScript)时不会更新 value 属性。发布到服务器的数据是“value”属性的原始值,而不是文本框中的文本。
The textareas in the form work fine, and I have checked javascript fired "onchange" and I can't find any... Help please!
表单中的 textareas 工作正常,我已经检查了 javascript 触发了“onchange”,但我找不到任何...请帮助!
Here is the HTML:
这是 HTML:
<form action="" method="post">
<div id="group-1" class="group case">
<a class="heading open">heading</a>
<input name="editform[0][class]" value="case" type="hidden">
<input name="editform[0][id]" value="2" type="hidden">
<div class="field">
<label>Name</label>
<input class="text" name="editform[0][name]" value="Mike Escarcaga" type="text" >
</div>
<div class="field">
<label>Title</label>
<input class="text" name="editform[0][title]" value="General Manager" type="text" >
</div>
<!-- repeated for each field -->
<div class="field" >
<label >Text</label>
<textarea class="ltext" name="editform[0][text]" >
Blah HTML, and more blah...
</textarea>
</div>
</div>
<!-- repeated for each group in the form (editform[1], editform[2], etc.) -->
</form>
回答by Quentin
The value attribute contains the defaultvalue for an input, not the live value.
value 属性包含输入的默认值,而不是实时值。
The DOM value property contains a live value.
DOM 值属性包含一个实时值。
回答by Mr Talha
Agree With @Quentin Dom Contain Live Value and HMTL Input contain Default Value for an input So for Changing the Default Value of the input use This Javascript Trick
同意@Quentin Dom Contain Live Value 和 HMTL Input 包含输入的默认值所以为了改变输入的默认值使用这个 Javascript 技巧
document.getElementById("myText").defaultValue = "Goofy";
Hope this save Others Time And Dont Forget to Rep+ This Answer if this helps :)
希望这可以节省其他人的时间,如果有帮助,请不要忘记回复 + 此答案:)