简体   繁体   中英

Struts2 textfield display length

I would like to make Struts2 textfield can display only 10 words but accept 20 words. See sample;

Want to display

1234567890

Want to accept

12345678901234567890

If I enter

1234567890123

And also want to display in textfield is 1234567890.Please share me some ideas and links

You can create your struts 2 text field which will accept max 20 character like below.

Code:
var value = "12345678912345678912";
$('#my').val(value.substr(0,10));

for dispaly only 10 digit you need to use javascript or jquery like below code.

Jquery Code:
 var value = "12345678912345678912"; $('#my').val(value.substr(0,10)); 

if value is not an String then you can use.

 var value = 12345678912345678912; $('#my').val(value.toString().substr(0,10)); 

Using this code you can achieve it

<s:textfield name="fieldname" value="12345678901234567890" size="10"/>

the display area of the field not exceed a 10 characters. However, the filed can contain more than 10 characters.

使用固定大小,例如:

<input type="text" value="12345678901234567890" style="width:50px" />

例如:输入类型=“文本”值=“12345678901234567890”style =“width:50px”maxlength =“20”

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM