-2
在此代码中,当您单击提交按钮时,它不显示警报消息。但是,它在删除对象和属性定义时起作用。为什么这个网页无法正常工作?
<--!DOCTYPE html>
<html>
<head>
<title>This is just a test</title>
<script src="script.js"></script>
</head>
<body>
<h1>This is going to be the search bar</h1>
<form>
<input type="text" id="BookName" name="Book1">
<input type="submit" id="Searchbtn" onclick="algo()">
</form>
<script>
function algo(){
alert("It is working");
};
var search = document.getElementById("BookName");
var bookDirectory = {};
bookDirectory.book1 = {
bookName = "book1",
bookTag1 = "MAIT",
bookTag2 = "3rd Semester"
};
bookDirectory.book2 = {
bookName = "book2",
bookTag1 = "NIEC",
bookTag2 = "1st Semester"
};
bookDirectory.book3 = {
bookName = "book3",
bookTag1 = "USIT",
bookTag2 = "5th Semester"
};
</script>
<h2 id="Book1">This is going to be the book</h2>
</body>
</html>
如果删除对象和属性定义?:
<!DOCTYPE html>
<html>
<head>
<title>This is just a test</title>
<script src="script.js"></script>
</head>
<body>
<h1>This is going to be the search bar</h1>
<form>
<input type="text" id="BookName" name="Book1">
<input type="submit" id="Searchbtn" onclick="algo()">
</form>
<script>
function algo(){
alert("It is working");
};
</script>
<h2 id="Book1">This is going to be the book</h2>
</body>
</html>
通过对象“然而,当您删除的对象和定义的搜索变量它只能”你是指? –
你应该仔细看看如何编写对象文字。现在他们的“定义”正在破坏你的代码,并且“algo”将永远不会被定义, – Teemu
你是否尝试过使用萤火虫来查看代码中是否有错误? – kojow7