使用內部的JavaScript如下:的HTML表單驗證
<script>
function validateForm()
{
var x=document.forms["myForm"]["firstName"].value;
if (x==null || x=="")
{
document.getElementById('usernameError').innerHTML = "Invalid First Name";
return false;
}
}
</script>
我將如何插入用戶錯誤文本在註釋中的位置:
<form name="myForm" action="someAction" method="post" onsubmit="return validateForm()" >
<fieldset class='step'>
<legend id="usernameError">Personal Information</legend>
<p>
<label for='firstName'>First Name:</label>
<input type='text' name='firstName' id='firstName' />
<!--Is JavaScript able to insert/append text here?-->
</p>
</fieldset>
你特林做 – Dinesh
你有什麼期望呢? – Puvanarajan
在html中插入文本interal javascript – user2948897