如何在js中制作一个简单答案的问题表单?我试过了
<!DOCTYPE html>
<html>
<head>
<meta charset = "utf-8"/>
<script>
function cipher1(){
var val ="theanswer";
if(val == (document.getElementById("cipher1").value)){
alert("correct");
}
}
</script>
</head>
<body id="bod">
<div id="cipher1"style="display:none;">
<input id="cipher1"type="text" value="write the answer here"/>
<input type="button" class="but"value="answercheck"onclick="cipher1()"/>
</div>
</body>
</html>但是它不起作用。请帮帮我!
发布于 2018-08-01 18:00:20
您的Id必须唯一。在您的代码中,您正在将'cipher1‘与div和输入字段相关联。您可以将文本字段的Id更改为cipher2。请参见以下代码:
function cipher1(){
var val ="theanswer";
if(val == (document.getElementById("cipher2").value)){
alert("correct");
}
} <div id="cipher1">
<input id="cipher2"type="text" value="write the answer here"/>
<input type="button" class="but"value="answercheck"onclick="cipher1()"/>
</div>
发布于 2018-08-01 17:56:36
首先尝试更改两个重复的ID
div id="**cipher1**"style="display:none;">
<input id="**cipher1**"type="text" value="write the answer here"/>然后从父div中删除显示样式
发布于 2018-08-01 18:14:15
您在页面上有重复的id (您在页面上只能有一个id ) cipher1
https://stackoverflow.com/questions/51630250
复制相似问题