我正在尝试使用javascript的onclick更改跨度的文本,但它无法正常工作。它非常简单,但我不确定为什么它不起作用
<div class="subscribe_block">
<h3><span>Stay Connected</span></h3>
<form method="post" action="" name="subscribeForm">
<span id="message"></span>
<p><input type="text" id="name" placeholder="Your Name" /></p>
<p><input type="text" id="email" placeholder="Email Id" /></p>
<p><input type="submit" value="subscribe" onClick='document.getElementById("message").value = "Thank you for subscribing";return false;' /></p>
</form>
</div>
答案 0 :(得分:1)
<div class="subscribe_block">
<h3><span>Stay Connected</span></h3>
<form method="post" action="" name="subscribeForm">
<span id="message"></span>
<p><input type="text" id="name" placeholder="Your Name" /></p>
<p><input type="text" id="email" placeholder="Email Id" /></p>
<p><input type="submit" value="subscribe" onClick='document.getElementById("message").innerHTML = "Thank you for subscribing";return false;' /></p>
</form>
</div>
使用'innerHTML'
代替'value'
。
答案 1 :(得分:1)
在onclick功能上,尝试更改,
'document.getElementById(“message”)。value =“感谢您订阅”;返回false;'
到
'document.getElementById("message").innerHTML = "Thank you for subscribing";return false;'
答案 2 :(得分:0)
只需将value
更改为innerHTML
<div class="subscribe_block">
<h3><span>Stay Connected</span></h3>
<form method="post" action="" name="subscribeForm">
<span id="message"></span>
<p><input type="text" id="name" placeholder="Your Name" /></p>
<p><input type="text" id="email" placeholder="Email Id" /></p>
<p><input type="submit" value="subscribe" onClick='document.getElementById("message").innerHTML = "Thank you for subscribing";return false;' /></p>
</form>
</div>
答案 3 :(得分:0)
使用InnerHtml
会设置您的Span
文字,但会回发,因此您将无法看到任何内容。删除表单标签,然后您就可以看到它。
<div class="subscribe_block">
<span id="message"></span>
<p><input type="text" id="name" placeholder="Your Name" /></p>
<p><input type="text" id="email" placeholder="Email Id" /></p>
<p><input type="submit" value="subscribe" onClick='document.getElementById("message").innerHTML= "Thank you for subscribing";return false;' /></p>