我创建了一个简单的演示,其中调用了外部java脚本。但它没有被onclick函数调用请咨询。
这里的例子。
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<script type="text/javascript"
src="http://code.jquery.com/jquery-latest.min.js"></script>
<script type="text/javascript" src="\\jsfiles\\JsScript.js"></script>
<title>Insert title here</title>
</head>
<body>
<h1>Project is working fine</h1>
<form action="HelloWorld" method="get">
<table border="2">
<tr>
<td>Username *: <input type="text" name="username"
id="username" /></td>
</tr>
<tr>
<td>Password *: <input type="password" name="pwd" id="password" /></td>
</tr>
<tr>
<td>Surname *: <input type="text" name="surname" /></td>
</tr>
<tr>
<td>Other Names *: <input type="text" name="names" /></td>
</tr>
<tr>
<td>Date of Birth *: <input type="text" name="dob" /></td>
</tr>
<tr>
<td>Email *: <input type="text" name="email" id="email"
onclick="checkmail()" /></td>
</tr>
<tr>
<td>Telephone: <input type="text" name="tel" /></td>
</tr>
<tr>
<td>Address *: <input type="text" name="add" /></td>
</tr>
<tr>
<td>Post Code *: <input type="text" name="ptc" /></td>
</tr>
<tr>
<td><input type="submit" value="Submit" onchange="checkmail()"></td>
</tr>
</table>
</form>
Js文件是。
function checkmail() {
alert("Callled");
alert(document.getElementById("email"));
}
提前感谢你的答案:)
答案 0 :(得分:2)
这一行错了:
<script type="text/javascript" src="\\jsfiles\\JsScript.js"></script>
将其更改为
<script type="text/javascript" src="jsfiles/JsScript.js"></script>
并添加onclick
事件:
<input type="submit" value="Submit" onclick="checkmail()">
答案 1 :(得分:0)
您正在使用带有按钮的'onchange'envent:
<input type="submit" value="Submit" onchange="checkmail()">
应该是onclick:
<input type="submit" value="Submit" onclick="checkmail()">