jQuery validation 与 tinyMCE兼容

<scripttype="text/javascript"src="../../lib/jquery.js"></script>

<scripttype="text/javascript"src="../../jquery.validate.js"></script>

<scripttype="text/javascript"src="tiny_mce.js"></script>

<scripttype="text/javascript">

tinyMCE.init({

mode:"textareas",

theme:"simple",

//updatevalidationstatusonchange

onchange_callback:function(editor){

tinyMCE.triggerSave();

$("#"+editor.id).valid();

}

});

$(function(){

varvalidator=$("#myform").submit(function(){

//updateunderlyingtextareabeforesubmitvalidation

tinyMCE.triggerSave();

}).validate({

rules:{

title:"required",

content:"required"

},

errorPlacement:function(label,element){

//positionerrorlabelaftergeneratedtextarea

if(element.is("textarea")){

label.insertAfter(element.next());

}else{

label.insertAfter(element)

}

}

});

validator.focusInvalid=function(){

//putfocusontinymceonsubmitvalidation

if(this.settings.focusInvalid){

try{

vartoFocus=$(this.findLastActive()||this.errorList.length&&this.errorList[0].element||[]);

if(toFocus.is("textarea")){

tinyMCE.get(toFocus.attr("id")).focus();

}else{

toFocus.filter(":visible").focus();

}

}catch(e){

//ignoreIEthrowingerrorswhenfocusinghiddenelements

}

}

}

})

</script>

相关推荐