Javascript 为什么我的代码是';s';e';没有定义?

Javascript 为什么我的代码是';s';e';没有定义?,javascript,html,Javascript,Html,我想对用户的输入进行评论。在我的代码中,e是一个函数,在onclick属性中,我们编写了一个函数,所以哪里出错了,请帮助。 你喜欢什么颜色? 红色 蓝色 远的 var Input=document.getElementById(“userInputss”); 编写(用户输入); 函数e(){ if(userInputss===userInput){ 文件。写(“好”);} else if(输入===用户输入){ document.write(“go”);} } 因为您的代码不在中,函数应为小

我想对用户的输入进行评论。在我的代码中,e是一个函数,在onclick属性中,我们编写了一个函数,所以哪里出错了,请帮助。


你喜欢什么颜色?
红色
蓝色 远的 var Input=document.getElementById(“userInputss”); 编写(用户输入); 函数e(){ if(userInputss===userInput){ 文件。写(“好”);} else if(输入===用户输入){ document.write(“go”);} }
因为您的代码不在
中,
函数应为小写。试试这个:

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

你喜欢什么颜色?
红色
蓝色 远的 var Input=document.getElementById(“用户输入”); 编写(用户输入); 函数e(){ 控制台日志(“单击”); /*我不确定这应该做什么: 如果(用户输入===用户输入){ 文件。书写(“良好”); }else if(输入===用户输入){ 文件。填写(“go”); }*/ }

查看控制台(F12->console)以查看单击。

我不清楚您在
e
函数中尝试执行的操作,但我构建此示例是为了帮助您:

var red=document.getElementById(“colorRed”)
,blue=document.getElementById(“colorBlue”);
//文件。书写(红色);
函数e(){
if(blue.checked==true){
文件。写下(“你喜欢蓝色”);
}else if(red.checked==true){
文件。写下(“你喜欢红色”);
}否则{
写下(“你什么都不喜欢”);
}
}

你喜欢什么颜色?
红色 蓝色
far
make it function e()它应该在脚本标记中有多个错误:userInputss不存在。关闭输入元素。函数。这就是我的真实代码,它是由错误的用户发送的。你想做什么?函数e没有意义,不客气。如果这个asnwer是有用的,向上投票并接受:)很好的研究,你能让这种类型的函数发生两次吗?取决于逻辑,如果它在循环中,是的,或者你调用递归模式,是的,谢谢,我刚想再学两门课。当用户同时点击这两门课时,它一定会显示你不喜欢任何东西,但它会显示你喜欢蓝色。为什么??
<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>