未调用Java脚本函数

Java Script Function not getting called

本文关键字:函数 脚本 Java 调用      更新时间:2024-03-15

我创建了一个简单的演示,其中调用了外部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"));
}

提前感谢您的回答:)

此行错误:

<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()">

您使用的是带有按钮的"onchange"环境:

   <input type="submit" value="Submit" onchange="checkmail()">

它应该是onclick:

   <input type="submit" value="Submit" onclick="checkmail()">