我想对用户的输入发表评论。在我的代码中,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>
答案 0 :(得分:0)
因为您的代码不在<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 - &gt;控制台)中查看点击次数。
答案 1 :(得分:0)
对于我在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>