我希望能够限制textarea中的字符数.我使用的方法在谷歌浏览器中效果很好,但在Firefox中很慢,并且在IE中不起作用.
使用Javascript:
function len(){
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);
}
}
Run Code Online (Sandbox Code Playgroud)
HTML:
<textarea id="user_post_textarea" name="user_post_textarea" cols="28" rows="1" onkeypress="len();" onkeyup="len();"></textarea>
Run Code Online (Sandbox Code Playgroud)
body元素底部的Javascript:
textarea=document.getElementById('user_post_textarea');
Run Code Online (Sandbox Code Playgroud) 我正在使用tinyMCe
我的项目.一切正常,但现在我想限制将插入tinyMce
textarea 的字符数
tinyMCE.init({
// General options
mode : "textareas",
theme : "simple",
plugins : "autolink,lists,pagebreak,style,table,save,advhr,advimage,advlink,emotions,media,noneditable,nonbreaking",
// Theme options
theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,fontselect,fontsizeselect",
theme_advanced_buttons2 : "bullist,numlist,|,outdent,indent,|,undo,redo,|,link,unlink,anchor,image,code,|,forecolor,backcolor",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
theme_advanced_statusbar_location : "bottom",
max_chars : "10",
max_chars_indicator : "lengthBox",
theme_advanced_resizing : true
});
Run Code Online (Sandbox Code Playgroud)
我用了 :-
max_chars : "10",
max_chars_indicator : "lengthBox",
Run Code Online (Sandbox Code Playgroud)
但仍然没有工作.谢谢.
我正在尝试在填写某些表单字段时启用提交按钮.我发现了一段可以运行的javascript代码,但我遇到了textarea fiel的问题,这是由tinymce转换的...如何捕获它?
我的HTML:
<form id="form_id1">
<fieldset>
<legend>Personal</legend>
Name: <input type="text" size="30" /><br />
Email: <input type="text" size="30" /><br />
Date of birth: <input type="text" size="10" /><br />
Address : <textarea size="30"></textarea><br />
</fieldset>
<input type="submit" value="Submit" />
</form>
Run Code Online (Sandbox Code Playgroud)
我的javascript:
$(document).ready(function()
{
$('#form_id1 input:submit').attr("disabled", true);
var textCounter = false;
$('#form_id1 input:text, #form_id1 textarea').keyup(check_submit);
function check_submit() {
$('#form_id1 input:text, #form_id1 textarea').each(function()
{
if ($(this).val().length == 0) {
textCounter = true;
return false;
}
else {
textCounter = false;
}
});
$('#form_id1 input:submit').attr("disabled", …
Run Code Online (Sandbox Code Playgroud)