使用 jquery 更改输入的大小

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11019746/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 10:06:09  来源:igfitidea点击:

Change the size of input with jquery

jqueryhtmldom

提问by Steven Jones

I have the following input:

我有以下输入:

<input id="input_2_2" 
       class="medium" 
       type="file" 
       tabindex="4" 
       size="20" 
       value="" 
       name="input_2">

I don't have access to the HTML therefore I would like to apply jQuery to change the size to "60".

我无权访问 HTML,因此我想应用 jQuery 将大小更改为“60”。

Please can someone help?

请问有人可以帮忙吗?

回答by WojtekT

You can use the .attrmethod:

您可以使用以下.attr方法:

$('#input_2_2').attr('size',60);

回答by ayyp

$("input_2_2").attr("size", "60");

$("input_2_2").attr("size", "60");

回答by Tom O

Use this:

用这个:

$("#input_2_2").attr("size", "60");

I believe that should work..

我相信这应该有效..

回答by Ricardo Binns

use attr();

使用attr();

like this:

像这样:

<input id="input_2_2" class="medium" type="file" tabindex="4" size="20" value="" name="input_2">

<input id="input_2_2" class="medium" type="file" tabindex="4" size="20" value="" name="input_2">

$("#input_2_2").attr("size","60");

$("#input_2_2").attr("size","60");

or, you can just set the widthof the element, in my opinion it's better.

或者,您可以设置width元素的 ,在我看来它更好。