【问题标题】:Javascript button event to change input text inside a HTML form [duplicate]用于更改 HTML 表单内的输入文本的 Javascript 按钮事件 [重复]
【发布时间】:2016-07-03 05:16:18
【问题描述】:

这是一个 .php 文件,我已经尝试了几种方法来完成这项工作,但我是 javascript 新手。当我在启用 document.write 的情况下运行它时,它显示按钮的 onclick 事件正在工作。但无论出于何种原因,我都找不到有关如何写入表单中输入文本元素的任何信息。有谁知道这应该如何工作?我必须将按钮放在表单内吗?谢谢。

<?php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<script type="text/javascript">
function setValue() {
    //document.write("122.0000");
    document.getElementById("someid").innerHTML="222.0000";
}
</script>
<center>
<button onclick="setValue()">Write value</button><br>
<center><form action="something.php" method="post" id ="inputForm">
Value: <input type="text" id="someid" /><br>
<input type="submit" />
</form>

【问题讨论】:

  • document.getElementById("someid").value="222.0000";

标签: javascript jquery html


【解决方案1】:

改变

document.getElementById("someid").innerHTML="222.0000";

document.getElementById("someid").value="222.0000";

这会将文本输入的value 设置为222.0000,而不是尝试更改innerHTML,这是开始和结束标记之间的内容(输入不存在)。

【讨论】:

    猜你喜欢
    • 2017-03-31
    • 1970-01-01
    • 1970-01-01
    • 2012-01-27
    • 2018-01-24
    • 2011-09-20
    • 1970-01-01
    • 1970-01-01
    • 2015-10-14
    相关资源
    最近更新 更多