【问题标题】:jQuery - find if text exists inside an iFramejQuery - 查找 iFrame 中是否存在文本
【发布时间】:2011-08-11 11:47:05
【问题描述】:

我在表单内的一个文本区域上使用 jQuery 所见即所得编辑器插件,我想对其应用验证。所见即所得的 jQuery 插件正在生成 iframe,所以我需要检测 if there is any text inserted inside the iframe 而不是文本区域。

<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> 

任何想法如何查找是否已在 iframe 中插入文本并在其旁边创建错误消息,例如 &lt;div id="err"&gt; This field is required&lt;/div&gt;?感谢您的帮助!

【问题讨论】:

    标签: jquery jquery-plugins jquery-selectors


    【解决方案1】:
    $('#id_message_bodyIFrame').contents().find('body').text()
    

    这会给你文本然后你可以添加

    .length() 
    

    到最后测试多长时间

    【讨论】:

    • 感谢您的快速回复。因此,要检查是否在框架内添加了文本,我应该这样做吗?if($('#id_message_bodyIFrame').contents().find('body').text().length()
    • 我会在测试后立即通知您。
    猜你喜欢
    • 1970-01-01
    • 2016-01-02
    • 2019-11-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多