开发者

Input element in javascript

开发者 https://www.devze.com 2023-03-18 18:00 出处:网络
How to set the size or width of an input element in javascript. I am using input_obj.size= \'40%\'开发者_JAVA百科;

How to set the size or width of an input element in javascript.

I am using input_obj.size= '40%'开发者_JAVA百科;

But, it is not working.


You set the size as per your own example — but it doesn't take a CSS length. It takes an integer (number of characters).

The width is set as per any other element: input_obj.style.width.


You should use style attribute:

  input_obj.style.width = '40%';


If input_obj is your input obj (which I assume according to the name ;))

input_obj.style.width = '100px';
0

精彩评论

暂无评论...
验证码 换一张
取 消