为什么我的代码是's 'e'没有定义
Why is my code's 'e' not defined?
我想评论一下用户的输入。在我的代码e是一个函数,在onclick属性我们写一个函数,所以我错了,请帮助。
<form>
What color do you prefer?<br>
<input type="radio" id="userInput" >Red<br>
<input type="radio" id="userInputs" >Blue
</form>
<button onclick="e()">far</button>
<script>
var Input = document.getElementById("userInputss");
document.write(userInputs);
Function e(){
if(userInputss===userInput){
document.write("good");}
else if(Input===userInputs){
document.write("go");}
}
</script>
</body>
</html>
对我来说不是很干净,你想在e
函数中做什么,但我建立了这个例子来帮助你:
var red = document.getElementById("colorRed")
, blue = document.getElementById("colorBlue");
//document.write(red);
function e(){
if(blue.checked == true){
document.write("You prefer Blue");
} else if (red.checked == true){
document.write("You prefer Red");
} else {
document.write("You prefer nothing");
}
}
<form>
What color do you prefer?<br>
<input type="radio" id="colorRed" >Red</input>
<input type="radio" id="colorBlue" >Blue</input>
</form>
<button onclick="e()">far</button>
因为你的代码不是在<script>
和function
应该是小写的。试试这个:
<form>
What color do you prefer?<br>
<input type="radio" id="userInput" >Red<br>
<input type="radio" id="userInputs" >Blue
</form>
<button onclick="e()">far</button>
<script>
var Input = document.getElementById("userInputs");
document.write(userInputs);
function e(){
console.log("Click");
/* I'm not sure what that is supposed to do:
if(userInputs===userInput){
document.write("good");
} else if(Input===userInputs){
document.write("go");
}*/
}
</script>
</body>
</html>
查看控制台(F12 ->控制台),查看点击。
相关文章:
- 如何消除代码中的未定义和其他问题
- 为什么这个JS代码打印未定义
- .val()返回未定义的.text返回随机代码
- 为什么这个代码没有定义,但没有2
- 在一个JavaScript文件中解析云代码定义和作业
- 如何将自定义代码与drupal合并
- 我使用谷歌标签管理器在我的网站上启动标签.变量“;未定义的“;在任何版本的Internet Explorer的自定义代码
- ...不是 JavaScript {自定义代码} 中的函数
- 如何将自定义代码添加到prestashop
- 对 HTML5 项目使用自定义C++代码
- 在通过Modernizr加载jQuery之后运行自定义代码
- 如何在Chrome DevTools中运行自定义代码
- 在ASP.net MVC 3应用程序的头文件中添加自定义代码/脚本
- Jquery验证,如果有错误,我如何运行自定义代码
- 如何通过自定义代码在wordpress中上传图像
- 轻松地将自定义代码转换为Drupal模块
- Google DFP异步标记上的自定义代码
- Sencha应用程序构建原生覆盖我们的自定义代码
- jQuery 选项卡在移动设备中不起作用 - 自定义代码
- 是否有可能在每个Ajax请求中执行自定义代码,而无需手动将该代码添加到Ext Js中的每个Ajax代码中?