开发者

jQuery - find if text exists inside an iFrame

开发者 https://www.devze.com 2023-02-28 19:56 出处:网络
I\'m using an jQuery wysiwyg editor pluginon one of my textareas inside a form and I want o apply validation to it. The wysiwyg jQuery plugin is generating an iframe so I need to detect if there is an

I'm using an jQuery wysiwyg editor plugin on one of my textareas inside a form and I want o apply validation to it. The wysiwyg jQuery plugin is generating an iframe so I need to detect if there is any text inserted inside the iframe not the text area.

<div class="wysiwyg" style="width: 581px;">
<ul class="panel" role="menu">
<div style="clear: both;"></div>
<iframe id="id_message_bodyIFrame" frameborder="0" src="javascript:false;" style="min-height: 170px; width: 573px;" tabindex="0">
<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
</head>
<body style="margin: 0px;">
my text I want to find if exists
<br _moz_dirty="">
</body>
</html>
</iframe>
</div>
<textarea id="id_message_body" title="Please add a message on the text box above." name="message_body" cols="70" rows="10" style="display: none;"></textarea>
<div id="req_message_body" class="req" style="display: none;">This is required</div>
</div> 

Any ideas how to find if text has been inserted inside the iframe and create a error message next to it like <div id="err"> Th开发者_JAVA百科is field is required</div>? I appreciate your help!


$('#id_message_bodyIFrame').contents().find('body').text()

that will give you text then you can just add

.length() 

to the end to test how long it is

0

精彩评论

暂无评论...
验证码 换一张
取 消