gpt4 book ai didi

javascript - 输入读取通过扫描短暂出现,然后立即重置。我该如何解决?

转载 作者:行者123 更新时间:2023-11-30 16:00:07 25 4
gpt4 key购买 nike

我无法让这个代码块正常工作:

    <script>
function Message(){
document.getElementById("sname").innerHTML = document.getElementById("name").value;
}
</script>
</head>
<body>
<form>
<table>
<tr>
<td style="width:20%">User Name:</td>
<td><input type="text" id="name" name="name" /></td>
</tr>
<tr><td>Password:</td><td><input type="password" name="password"/></td></tr>
<tr>
<td style="text-align:right">
<input type="submit" onclick="Message()"/>
</td>
</tr>
</table>
</form>
<div>
<p>Hi <span id="sname">0</span></p>
</div>
</body>

最佳答案

试试这个

</head>
<body>
<form onsubmit="event.preventDefault();">
<table>
<tr>
<td style="width:20%">User Name:</td>
<td><input type="text" id="name" name="name" /></td>
</tr>
<tr><td>Password:</td><td><input type="password" name="password"/></td></tr>
<tr>
<td style="text-align:right">
<input type="submit" onclick="Message()"/>
</td>
</tr>
</table>
</form>
<div>
<p>Hi <span id="sname">0</span></p>
</div>

<script>
function Message(){ document.getElementById("sname").innerHTML = document.getElementById("name").value; return false;}

</script>
</body>

关于javascript - 输入读取通过扫描短暂出现,然后立即重置。我该如何解决?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37902546/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com