gpt4 book ai didi

javascript - maxlength 不适用于某些元素

转载 作者:行者123 更新时间:2023-11-30 13:05:19 25 4
gpt4 key购买 nike

好的,所以我正在构建一个自定义注册页面,当然还涉及到 javascript 输入验证。

在该验证中,我使用了 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>

最佳答案

没有 maxlength 这样的东西 - 请改用 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>

关于javascript - maxlength 不适用于某些元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15901664/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com