2013-04-09 81 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