Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/399.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用jquery/javascript更改特定元素的maxlength?_Javascript_Jquery - Fatal编程技术网

如何使用jquery/javascript更改特定元素的maxlength?

如何使用jquery/javascript更改特定元素的maxlength?,javascript,jquery,Javascript,Jquery,我有以下内容: <input name="someelement" title="Title" class="someclass" id="someid" maxlength="255" value="Some Value" /> 或 或者像塔奈丁说的: $('#someid').attr('maxlength', 100); 或 或者像塔奈丁说的: $('#someid').attr('maxlength', 100); 您可以使用javascriptmaxLength属性

我有以下内容:

<input name="someelement" title="Title" class="someclass" id="someid" maxlength="255" value="Some Value" />

或者像塔奈丁说的:

$('#someid').attr('maxlength', 100);

或者像塔奈丁说的:

$('#someid').attr('maxlength', 100);
您可以使用javascript
maxLength
属性

document.getElementById("someid").maxLength = 100;
Ref:

您可以使用javascript
maxLength
属性

document.getElementById("someid").maxLength = 100;

参考:

回答问题的第二部分:

Javascript:

JQuery:

注意

  • 它是
    maxLength
    (大写L)
  • 值最好以字符串(引号中)的形式提供,尽管属性本身的实现长度相同

  • 回答问题的第二部分:

    Javascript:

    JQuery:

    注意

  • 它是
    maxLength
    (大写L)
  • 值最好以字符串(引号中)的形式提供,尽管属性本身的实现长度相同
  • 是的,你可以

    使用JavaScript:

    document.getElementById("someid").setAttribute("maxlength", 100);
    

    使用jQuery:

    $('#someid').attr('maxlength', 100);
    
    祝你好运

    是的,你可以

    使用JavaScript:

    document.getElementById("someid").setAttribute("maxlength", 100);
    

    使用jQuery:

    $('#someid').attr('maxlength', 100);
    
    祝你好运

    还有$('someid').attr('maxlength',100);可以更快。也可以是$('someid').attr('maxlength',100);可能更快。
    document.getElementById("someid").maxLength = 100;
    
    $('#someid').attr('maxlength', 100);