textarea字符限制
- 论坛
- textarea字符限制
9 浏览
textarea字符限制
我希望能够限制文本区域中的字符数。我目前使用的方法在Google Chrome中效果很好,但在Firefox中速度较慢,在IE中则不起作用。
Javascript:
function len() { var t_v = textarea.value; if (t_v.length > 180) { long_post_container.innerHTML = long_post; post_button.className = post_button.className.replace('post_it_regular', 'post_it_disabled'); post_button.disabled = true; } else { long_post_container.innerHTML = ""; post_button.className = post_button.className.replace('post_it_disabled', 'post_it_regular'); post_button.disabled = false; } if (t_v.length > 186) { t_v = t_v.substring(0, 186); } }
HTML:
在
元素底部的Javascript代码:textarea = document.getElementById('user_post_textarea');