This script allows you to set a limit on the number of characters a user can enter into a textarea or text field, like so:
Step 1 - Create Function
Insert the following code into the page head:
Step 2 - Create Text Area
Use the following code to create the form and text area (if necessary, change the name of the form and text area to suit your needs):
To create a single-line text field instead of a text area, use the following code:
The result looks like this:
Note: You can have multiple text areas and/or fields on the same page using the same function. Just make sure you give each field a unique name.
CÁCH KHÁC: SỬ DỤNG CSS
Tham khảo trang gốc: http://jsfiddle.net/csYjC/1131/
Tham khảo trang gốc: http://jsfiddle.net/csYjC/1131/
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam consectetur venenatis blandit. Praesent vehicula, libero non pretium vulputate, lacus arcu facilisis lectus, sed feugiat tellus nulla eu dolor. Nulla porta bibendum lectus quis euismod. Aliquam volutpat ultricies porttitor. Cras risus nisi, accumsan vel cursus ut, sollicitudin vitae dolor. Fusce scelerisque eleifend lectus in bibendum. Suspendisse lacinia egestas felis a volutpat.
</div>
body {
margin: 20px;
}
.text {
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
line-height: 16px; /* fallback */
max-height: 32px; /* fallback */
-webkit-line-clamp: 2; /* number of lines to show */
-webkit-box-orient: vertical;
}
Kết quả:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam consectetur venenatis blandit. Praesent vehicula, libero non pretium vulputate, lacus arcu facilisis lectus, sed feugiat tellus nulla eu dolor. Nulla porta bibendum lectus q
Nhận xét
Đăng nhận xét