亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

錯誤 onchange (function) 未在 HTMLSelectElement

錯誤 onchange (function) 未在 HTMLSelectElement

滄海一幻覺 2023-07-20 14:57:28
我是編程初學者,今天我需要你的幫助?。ㄕ?'()我想創建一個調查,所以我開始編碼,出現錯誤,我在互聯網上搜索了很多,但沒有解決方案。有我的html和js代碼。/*the code isn't finish, this error block me(code name is sur.js*/let choi;let choix1 = 1;let choix2 = 1;let choix3 = 1;function submit(){console.log(choi);}function changer(){getElementById('survey');choi= sel.options[sel.selectedIndex];console.log(choi);}<!DOCTYPE html><html><head><title>Robotale v8 : surveys</title><link rel="icon" href="https://www.mediafire.com/convkey/a940/qp7vky5trrp8hmzzg.jpg"/></head><body style="background-color:#000000"><br><a href="Index.html"><img src="https://www.mediafire.com/convkey/6586/bb0x08ff0tvjhepzg.jpg" onclick="redirection()"/></a><br><font face= "Verdana" size="4" color="#3399ff">The Robotale Website is here for your Robotale time!!!</p><br><p>Surveys:</p><br><form><label for="survey">Your feedback about this website!!!How do you like it?</label><select id="survey" name="survey" type="datalist" onchange="changer();"><datalist id="surveys"><option value="No">Nope!!!</option><option value="Yes">Yes!!!</option><option value="liv">THIS WEBSITE IS MY LIFE IF YOU DELETE IT I WILL DIE!!!(calm down please)</option></datalist></form><a href="Index.html">link to principal page</a><br><br><input type="submit" value="Send your feedback" id="food" onclick="submit()"><br><script src"sur.js"></script></html>
查看完整描述

1 回答

?
Helenr

TA貢獻1780條經驗 獲得超4個贊

您沒有指定對選擇器 - 的不完整調用getElementById('survey');。規則是使用document,并且你需要這樣寫 - document.getElementById('survey');。


接下來,您有一個未定義的變量sel,我的意思是該變量填充了來自 的數據document.getElementById('survey');。結果是這樣的——let sel = document.getElementById('survey');


現在運行此代碼并嘗試從下拉列表中選擇一個值。沒有錯誤。


應該是這樣嗎?


/*the code isn't finish, this error block me(code name is sur.js*/

let choi;

let choix1 = 1;

let choix2 = 1;

let choix3 = 1;

function submit(){

console.log(choi);

}

function changer(){

let sel = document.getElementById('survey');

choi= sel.options[sel.selectedIndex];

console.log(choi);

}

<!DOCTYPE html>

<html>

<head>

<title>Robotale v8 : surveys</title>

<link rel="icon" href="https://www.mediafire.com/convkey/a940/qp7vky5trrp8hmzzg.jpg"/>

</head>

<body style="background-color:#000000">

<br>

<a href="Index.html">

<img src="https://www.mediafire.com/convkey/6586/bb0x08ff0tvjhepzg.jpg" onclick="redirection()"/>

</a>

<br>

<font face= "Verdana" size="4" color="#3399ff">The Robotale Website is here for your Robotale time!!!</p>

<br>

<p>Surveys:</p>

<br>

<form>

<label for="survey">Your feedback about this website!!!How do you like it?</label>

<select id="survey" name="survey" type="datalist" onchange="changer();">

<datalist id="surveys">

<option value="No">Nope!!!</option>

<option value="Yes">Yes!!!</option>

<option value="liv">THIS WEBSITE IS MY LIFE IF YOU DELETE IT I WILL DIE!!!(calm down please)</option>

</datalist>

</form>

<a href="Index.html">link to principal page</a>

<br>

<br>

<input type="submit" value="Send your feedback" id="food" onclick="submit()">

<br>

<script src"sur.js"></script>


</html>


查看完整回答
反對 回復 2023-07-20
  • 1 回答
  • 0 關注
  • 123 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號