2013-04-09 93 views
1

好吧,所以我構建了一個自定義註冊頁面,當然還有涉及到javascript輸入驗證。maxlength對某些元素不起作用

在驗證中,我使用maxlength屬性來驗證輸入的長度 - 這是一種雙重安全性,但它很容易獲得元素的屬性,我認爲「爲什麼不呢?」。

但是,我發現在我的某些表單輸入元素上屬性爲undefined,並在其他表單上正確定義。

我一直在看幾天的HTML,我不明白爲什麼它沒有在一些元素上定義,但對大多數作品。

我已經構建了一個工作和非工作元素都存在的頁面,雖然它不是它應該如何放在一起。

Here is a link到那,下面是一個非工作形式的例子。我希望你們中的一些人能看到它有什麼問題!

代碼:

<div id="9irBGsdLR"> 
    <form method="POST" class="form" name="frontContent" id="forntContent" style="margin-bottom:15px;"> 
    <div id="9button" style="float:right;"> 
     <img onclick="deleteElement(&#39;9&#39;, &#39;9irBGsdLR&#39;, this, &#39;actions/delete.php&#39;)" alt="delete" style="border:0px;float:right;cursor:pointer;" src="./validationNotWorking_files/close_32.png"> 
    </div> 
    <input type="text" name="id" style="display:none;" value="9"> 
    <label class="inputlabel softInputlabel" style="width:20%;">Headline: </label> 
    <input maxlenght="50" type="text" name="title" id="title" class="inputfield" contenttype="text" value="Praesent rhoncus faucibus elementum"> 
    <label class="inputlabel softInputlabel" style="width:20%;">Succession: </label> 
    <input maxlenght="4" type="text" name="succession" id="title" class="inputfield" contenttype="numerical" value="50"> 
    <label class="inputlabel softInputlabel" style="width:20%;">Content: </label> 
    <textarea class="formField" style="width:75%;height:300px;" name="content"></textarea> 
    </form> 
    <hr> 
</div> 
+1

maxlenght = 「50」? – 2013-04-09 12:19:15

回答

3

有作爲maxlenght沒有這樣的事 - 用maxlength代替。

這是jsFiddle

HTML:

<div id="9irBGsdLR"> 
    <form method="POST" class="form" name="frontContent" id="forntContent" style="margin-bottom:15px;"> 
     <div id="9button" style="float:right;"> 
      <img onclick="deleteElement(&#39;9&#39;, &#39;9irBGsdLR&#39;, this, &#39;actions/delete.php&#39;)" alt="delete" style="border:0px;float:right;cursor:pointer;" src="./validationNotWorking_files/close_32.png"> 
     </div> 
    <input type="text" name="id" style="display:none;" value="9"> 
    <label class="inputlabel softInputlabel" style="width:20%;">Headline: </label> 
    <input maxlength="50" type="text" name="title" id="title" class="inputfield" contenttype="text" value="Praesent rhoncus faucibus elementum"> 
    <label class="inputlabel softInputlabel" style="width:20%;">Succession: </label> 
    <input maxlength="4" type="text" name="succession" id="title" class="inputfield" contenttype="numerical" value="50"> 
    <label class="inputlabel softInputlabel" style="width:20%;">Content: </label> 
    <textarea class="formField" style="width:75%;height:300px;" name="content"></textarea> 
    </form> 
    <hr> 
</div> 
+1

我可能已經檢查了100次拼寫,並且仍然弄錯了:D ...感謝您的支持! :) – Fireworm 2013-04-09 12:49:14

+0

@Fireworm不用擔心男人,有時也發生在我身上! – lifetimes 2013-04-09 12:50:25