如何访问jquery wysiwyg插件的textarea?

发布于 2024-08-19 03:42:13 字数 1093 浏览 3 评论 0原文

我正在使用 wysiwyg 插件 (http://code.google.com/p/jwysiwyg/) 对于一个项目,如果 textarea 为空,或者在提交表单之前不向用户发出警报,我会得到,但这个插件创建了一个 iframe,但我无法获取它。

这是由插件生成的 html,该插件将 textarea 替换为 id #testo

<p><div class="wysiwyg" style="width: 896px;"> 

    <div style="clear: both;"><!-- --></div>
    <iframe tabindex="0" id="testoIFrame" style="min-height: 130px; width: 888px;" src="javascript:false;" frameborder="0">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
</head>
<body style="margin: 0px; font-family: Arial,Helvetica,sans-serif; font-size: 12px;">

your text here

</body>
</html>

</iframe>

    </div>

    <textarea style="display: none;" id="testo" name="testo" rows="8">
    </textarea></p>

textarea 不会显示。 如果 iframe 中没有文本,我将向内容 div 添加一个类:

$('#testo').addClass('border');

i'm using wysiwyg plugin (http://code.google.com/p/jwysiwyg/) for a project and i would get if textarea is empty or not to give to users an alert before submitting the form but this plugin create an iframe and i can't get it.

this is html generated by plugin that replace textarea with id #testo

<p><div class="wysiwyg" style="width: 896px;"> 

    <div style="clear: both;"><!-- --></div>
    <iframe tabindex="0" id="testoIFrame" style="min-height: 130px; width: 888px;" src="javascript:false;" frameborder="0">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
</head>
<body style="margin: 0px; font-family: Arial,Helvetica,sans-serif; font-size: 12px;">

your text here

</body>
</html>

</iframe>

    </div>

    <textarea style="display: none;" id="testo" name="testo" rows="8">
    </textarea></p>

textarea is not displayed.
if there's no text in iframe i would add a class to content div with:

$('#testo').addClass('border');

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

海风掠过北极光 2024-08-26 03:42:13

我相信这会起作用..

$('#your_form_id').submit(
  function(){
    $testoTextarea = $('#testo');
    $testoFrame = $('#testoIFrame');
    if ($testoTextare.val() == '')
       {
         $testoFrame.addClass('border');
         return false;
       }
    return true;
  }
);

问题是提交时插件必须将文本放回文本区域才能传递到下一页..
此外,iframe 采用的 id 是原始 textareas id + 'IFrame',因此很容易识别它......

I believe this would work ..

$('#your_form_id').submit(
  function(){
    $testoTextarea = $('#testo');
    $testoFrame = $('#testoIFrame');
    if ($testoTextare.val() == '')
       {
         $testoFrame.addClass('border');
         return false;
       }
    return true;
  }
);

The thing is that on submit the plugin will have to put the text back to the textarea for it to get passed to the next page..
Also the iframe takes an id that is the original textareas id + 'IFrame' so it is easy to identify it ...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文