javascript能否直接獲得html表單數(shù)據(jù)
<body>
<form action="index.html" method="post">請(qǐng)輸入您的姓名
? ? <input type="text" name="age" id="age">
? ? <input type="submit" value="提交">
</form>
<script type="text/JavaScript">
var myage=document.getElementById("age").value;
if(myage<=44)
? {document.write("青年");}
else if(myage<=59)?
? {document.write("中年人");}
else if(myage<=89)
? {document.write("老年人");}
else ? ? ? ?
? {document.write("長(zhǎng)壽老年人");}
</script>
</body>
沒(méi)成功(╯‵□′)╯︵┻━┻是哪錯(cuò)了還是根本就不行
2016-07-04
你得寫(xiě)個(gè)function a,判斷語(yǔ)句放在方法中,之后在提交的input中,來(lái)響應(yīng)鼠標(biāo)事件,onclick="a()"。?
2016-07-04
type=submit會(huì)提交到你的form表單定義的action中
2016-07-04
<form action="index.html" method="post">請(qǐng)輸入您的年齡:
? ? <input type="text" name="age" id="age">
</form>
<input type="button" value="提交測(cè)試" onclick="a()">
<script language="javascript">
? ? function a(){
? ? ? ? var myage= document.getElementById("age").value;
? ? ? ? if(myage<=44)
? ? ? ? ? {document.write("青年");}
? ? ? ? else if(myage<=59)?
? ? ? ? ? {document.write("中年人");}
? ? ? ? else if(myage<=89)
? ? ? ? ? {document.write("老年人");}
? ? ? ? else ? ? ? ?
? ? ? ? ? {document.write("長(zhǎng)壽老年人");}
? ? }
</script>
2016-07-04
val是獲得value屬性中的值,而不是內(nèi)容