我寫了一個簡單的javaScript函數來驗證所需的用戶名字段使用JS爲我的學習目的。無法在Chrome中設置斷點
我面臨兩個問題 -
- 在提交按鈕,onclick事件處理程序不調用
checkRequired
方法,以及窗體回。 - 我無法在chrome調試器中設置斷點。
- 即使僅在代碼中使用調試器也不會將控件 調試器斷點。
TaskManager.js
function checkRequired() {
debugger;
var userName = document.getElementById("txtUserName");
if (userName.length == 0) {
alert("username is required attribute");
return false;
}
return true;
}
AddNewUser函數:
<html>
<head>
<title>Add new User</title>
<style type="text/css" media="all">
button {
width: 65px;
}
</style>
<script src="TaskManager.js" type="text/javascript"></script>
</head>
<body>
<form method="post" action="AddNewUser.html" style="width: 560px; height: 850px; margin-left: 10px; margin-top: 10px">
<fieldset>
<legend>New User</legend>
<table>
<tr>
<td>
<label>User Name:</label></td>
<td>
<input type="text" id="txtUserName" name="User Name" maxlength="10" /></td>
</tr>
<tr>
<td>
<button id="btnSubmit" type="submit" onclick="checkRequired()">Add User</button>
</td>
<td>
<button id="btnCancel">Cancel</button>
</td>
</tr>
</table>
</fieldset>
</form>
</body>
</html>
感謝您的幫助來解決問題。
您是否檢查控制檯是否有錯誤? – gdoron
是的,我在控制檯中看不到任何錯誤。 – Abhijeet