为了账号安全,请及时绑定邮箱和手机立即绑定

错误 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 关注
  • 99 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信