第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定

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>

沒成功(╯‵□′)╯︵┻━┻是哪錯了還是根本就不行

正在回答

4 回答

你得寫個function a,判斷語句放在方法中,之后在提交的input中,來響應(yīng)鼠標(biāo)事件,onclick="a()"。?

0 回復(fù) 有任何疑惑可以回復(fù)我~
#1

阿皎就是煢兔丶 提問者

我試了,但輸入什么數(shù)都是輸出青年
2016-07-04 回復(fù) 有任何疑惑可以回復(fù)我~
#2

阿皎就是煢兔丶 提問者

好了,我把獲取表單id也放在函數(shù)里就好了
2016-07-04 回復(fù) 有任何疑惑可以回復(fù)我~
#3

Molly喜 回復(fù) 阿皎就是煢兔丶 提問者

點(diǎn)擊submit是向?yàn)g覽器發(fā)送表單數(shù)據(jù)。如果想讓js處理數(shù)據(jù),需要一個事件,比如在button中onclick事件。 并且糾正一下下面,innerHTML不能用于獲取input的輸入內(nèi)容,因?yàn)閕nput內(nèi)容隱藏在value中,需要用.value獲取。
2017-12-11 回復(fù) 有任何疑惑可以回復(fù)我~

type=submit會提交到你的form表單定義的action中

0 回復(fù) 有任何疑惑可以回復(fù)我~

<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>


0 回復(fù) 有任何疑惑可以回復(fù)我~

val是獲得value屬性中的值,而不是內(nèi)容

0 回復(fù) 有任何疑惑可以回復(fù)我~
#1

阿皎就是煢兔丶 提問者

那應(yīng)該用什么
2016-07-04 回復(fù) 有任何疑惑可以回復(fù)我~
#2

卡蘭尼克 回復(fù) 阿皎就是煢兔丶 提問者

用innerHTML獲得內(nèi)容
2016-10-28 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消

javascript能否直接獲得html表單數(shù)據(jù)

我要回答 關(guān)注問題
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號