-1

jsfiddle で資金移動の検証を実装しました。jsfiddle では問題なく動作しますが、localhost では動作しません。私はワンプを使っています。

ここに私のjsfiddleリンクがあります - http://jsfiddle.net/BzdfN/31/

しかし、これをlocalhost.itsで実装しているときは機能しません。

私のhtmlコードは

<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="validate.js"></script>
<title> Infy Bank Fund Transfer Entry Page </title>
</head>
<body>
<table class="layout" border="0" width="90%" align="center">
<form name="addcust" method ="POST" action ="http://localhost:8080/myapp/jsp/AddCustomerJSP.jsp">
    <td colspan="2">
    <table border="0" width="70%" align="center">
<tr>
    <td align="center" colspan="2">
    <div class="heading2">Infy Bank</div>
    </td>
</tr>
<tr>
    <td align="center" colspan="2"><p class="heading3">Fund transfer</p></td>
</tr>
<tr>
</tr>
<tr>
</tr>
<tr>
    <td>Payers account no<span class="mandatory">*</span></td>
    <td><input type="text" name="text10" id="text10" size="25" />
<div width="100%" id="equal"><a href="#" class="button button-green"></a></div>
    </td>
</tr>
<!--<tr>
    <td>Payees account no<span class="mandatory">*</span></td>
    <td>
        <input type="text" name="name" value=2008 maxlength="25">   
    </td>
</tr>
<tr>
    <td>Amount<span class="mandatory">*</span></td><td><input type="text" Value=500 name="state" maxlength="25"></td>
</tr>
<tr>
    <td>Description<span class="mandatory">*</span></td><td><input type="text" name="pin" value=self maxlength="6"></td>
</tr>
<tr>
    <td><span class="mandatory">*mandatory field</span></td>
    <td><input type="submit" name="AccSubmit" value="Submit" onClick="return validatebal();">
        <input type="reset" name="res" value="Reset"></td>
</tr>-->
</form>
</table>
<p align="right"><a href="homepage.html">Home</a></p>
</body>
</html>

私のvalidate.jsは

 $("#text10").keyup(function(){
        $("#text10").blur();
        $("#text10").focus();
});
$("#text10").change(function(){
var name = $('#text10').val();
         var numbers = /^[0-9]+$/;   
         var specialChars = "<>@!#$%^&*()_+[]{}?:;|'\"\\,./~`-=";



    if (name == "" || name == " " )
        {
             $("#equal").show();
             $("#equal a").html("please enter account number");

        }


    else if(name.match(numbers))
    {
               $("#equal").hide();
             $("#equal a").html("correct account number");   //  alert('All Boxes have elements.');
    }

    else if(name.match(specialChars))
    {
               $("#equal").show();
             $("#equal a").html("correct account number");   //  alert('All Boxes have elements.');
    }
  else 
        {
             $("#equal").show();
             $("#equal a").html("please check your account number  correctly");

        }

});

だから、私が間違っていることを教えてください。助けてください

4

3 に答える 3

1

jsfFiddle では、コードはonloadイベントで実行されます。

しかし、スクリプトの内容に含めるvalidate.jsと、head配置した場所ですぐに実行され<script src="validate.js"></script>ます。したがって、スクリプトの実行時に要素が DOM にないため、jQuery セレクターは要素を検出しません。

あなたにはさまざまな可能性があります。

  1. のコンテンツをラップしvalidate.jsますjQuery(function() { /*your code of validate.js **/ })

  2. もう 1 つの可能性は<script src="validate.js"></script>、ドキュメントを head に配置する代わりに、ドキュメントの最後に配置することです。

  3. この時点でDOMにあるかどうかは関係$(document).on("keyup","#text10", function() { /* .... */ }); ありません。#text10

于 2013-10-19T11:31:33.930 に答える