我想检查我的textarea,如果用户没有填写消息,它会提示一条警告消息。然而,我的textarea似乎被nicEdit textarea取代了。
<head>
<script type="text/javascript" src="/ecover/common/editor/editor.js"></script>
<script type="text/javascript">
bkLib.onDomLoaded(function() {new nicEditor({fullPanel : true}).panelInstance('MESSAGE');});
function validate()
{
if(document.mainfrm.MESSAGE.value=="")
{
alert("Please enter the value Message");
document.mainfrm.MESSAGE.focus();
return false;
}
return true;
}
</script>
</head>
<body>
<form name="mainfrm" method="post" action="addMessageRep.jsp" onSubmit="return validate();">
<textarea id="MESSAGE" name="MESSAGE" cols="80" rows="20" ></textarea>
</form>
</body>
var isTextarea = (e.nodeName.toLowerCase() == "textarea");
if(isTextarea || this.options.hasPanel) {
var ie7s = (bkLib.isMSIE && !((typeof document.body.style.maxHeight != "undefined") && document.compatMode == "CSS1Compat"))
var s = {width: newX+'px', border : '1px solid #ccc', borderTop : 0, overflowY : 'auto', overflowX: 'hidden' };
s[(ie7s) ? 'height' : 'maxHeight'] = (this.ne.options.maxHeight) ? this.ne.options.maxHeight+'px' : null;
this.editorContain = new bkElement('DIV').setStyle(s).appendBefore(e);
var editorElm = new bkElement('DIV').setStyle({width : (newX-8)+'px', margin: '4px', minHeight : newY+'px'}).addClass('main').appendTo(this.editorContain);
e.setStyle({display : 'none'});
editorElm.innerHTML = e.innerHTML;
if(isTextarea) {
editorElm.setContent(e.value);
this.copyElm = e;
var f = e.parentTag('FORM');
if(f) { bkLib.addEvent( f, 'submit', this.saveContent.closure(this)); }
}
editorElm.setStyle((ie7s) ? {height : newY+'px'} : {overflow: 'hidden'});
this.elm = editorElm;
}
测试步骤:
答案 0 :(得分:0)
获取niceEditor textarea的值,尝试:
var nicInstance = nicEditors.findEditor('MESSAGE');
var messageContent = nicInstance.getContent();
//then check for messageContent
<强>更新:: 强>
bkLib.onDomLoaded(function() {new nicEditor({fullPanel : true}).panelInstance('MESSAGE');});
function validate()
{
var nicInstance = nicEditors.findEditor('MESSAGE');
var messageContent = nicInstance.getContent();
//since nicEditor sets default value of textarea as <br>
//we are checking for it
if(messageContent=="<br>") {
alert("Please enter the value Message");
document.mainfrm.MESSAGE.focus();
return false;
}
else {
alert("valid");
}
return true;
}
演示:: jsFiddle