javascript能否直接獲得html表單數(shù)據(jù)
<body>
<form action="index.html" method="post">請輸入您的姓名
? ? <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("長壽老年人");}
</script>
</body>
沒成功(╯‵□′)╯︵┻━┻是哪錯了還是根本就不行
2016-07-04
你得寫個function a,判斷語句放在方法中,之后在提交的input中,來響應(yīng)鼠標(biāo)事件,onclick="a()"。?
2016-07-04
type=submit會提交到你的form表單定義的action中
2016-07-04
<form action="index.html" method="post">請輸入您的年齡:
? ? <input type="text" name="age" id="age">
</form>
<input type="button" value="提交測試" 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("長壽老年人");}
? ? }
</script>
2016-07-04
val是獲得value屬性中的值,而不是內(nèi)容