验证FCKeditor

发布于 2024-09-24 17:42:00 字数 42 浏览 5 评论 0原文

如何使用 javascript 验证 FCKeditor 的必填字段。

how can FCKeditor be validated for required field using javascript.

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

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

发布评论

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

评论(4

哭了丶谁疼 2024-10-01 17:42:00

试试这个,

var EditorInstance = FCKeditorAPI.GetInstance('message') ; 
if(EditorInstance.EditorDocument.body.innerText.length<=0)
{
alert("This firld is mandatory");
EditorInstance.EditorDocument.body.focus();
return false;
}

来源:

http://dreamtechworld.wordpress.com/2008/12/06/validating-firld-in-fckeditor-using-javascript/

Try this,

var EditorInstance = FCKeditorAPI.GetInstance('message') ; 
if(EditorInstance.EditorDocument.body.innerText.length<=0)
{
alert("This firld is mandatory");
EditorInstance.EditorDocument.body.focus();
return false;
}

Source:

http://dreamtechworld.wordpress.com/2008/12/06/validating-firld-in-fckeditor-using-javascript/

伴我老 2024-10-01 17:42:00

使用 FireBug,查看它正在更新哪些隐藏的 textarea。然后检查该元素。

if (document.getElementById('fckinstance').innerHTML === '') {
    alert('required field');
}

这只是一个例子。它可能也不会使用这样的 id ,因为同一页面上有多个实例。

FCKeditor 替换的 textarea 可能是保存其 HTML 的区域。

另请注意,FCKeditor 可能看起来是空白的,即使其中有 HTML。

Use FireBug, and see what hidden textarea it is updating. Then check that element.

if (document.getElementById('fckinstance').innerHTML === '') {
    alert('required field');
}

That is just an example. It probably doesn't use an id like that either, because of multiple instances on the same page.

The textarea that FCKeditor replaces is probably the one that holds its HTML.

Note too, the FCKeditor can seem blank, even though there is HTML in it.

¢蛋碎的人ぎ生 2024-10-01 17:42:00

要验证 FCKeditor 是否为空,请创建以下函数并在验证包含 TEXTAREA 的编辑器时调用它:

function FCKCopy() {
    for (var i = 0; i < parent.frames.length; ++i ) {
        if (parent.frames[i].FCK)
            parent.frames[i].FCK.UpdateLinkedField();
    }
}

然后添加另一个函数以从 TEXTAREA 的值中剥离 HTML 标签:

function stripHTML(oldString) {
    var matchTag = /<(?:.|\s)*?>/g;
    return $.trim(oldString.replace(matchTag, ""));
}

在上面的函数中使用了 jQuery 的修剪函数。使用 jQuery 或用 java 脚本的一些修剪功能替换它,例如:

function trimIt(text) {
    rwhite = /\s/;

    trimLeft = /^\s+/;
    trimRight = /\s+$/;

    if ( !rwhite.test( "\xA0" ) ) {
        trimLeft = /^[\s\xA0]+/;
        trimRight = /[\s\xA0]+$/;
    }

    return text.toString().replace( trimLeft, "" ).replace( trimRight, "" );
}

现在您可以检查 TEXTAREA 的值,如下所示:

if (stripHTML($('message').val()) == '') {
     alert('Please enter Message.');
}

希望它能像我一样工作。

玩得开心

To Validate FCKeditor for being empty, create below function and call it whenever going to validate your editor containing TEXTAREA:

function FCKCopy() {
    for (var i = 0; i < parent.frames.length; ++i ) {
        if (parent.frames[i].FCK)
            parent.frames[i].FCK.UpdateLinkedField();
    }
}

Then add another function to Strip HTML tags from TEXTAREA's value:

function stripHTML(oldString) {
    var matchTag = /<(?:.|\s)*?>/g;
    return $.trim(oldString.replace(matchTag, ""));
}

In above function used jQuery's trim function. Use jQuery or replace it with some trimming function for java script such as:

function trimIt(text) {
    rwhite = /\s/;

    trimLeft = /^\s+/;
    trimRight = /\s+$/;

    if ( !rwhite.test( "\xA0" ) ) {
        trimLeft = /^[\s\xA0]+/;
        trimRight = /[\s\xA0]+$/;
    }

    return text.toString().replace( trimLeft, "" ).replace( trimRight, "" );
}

Now you can check value of TEXTAREA for example as below:

if (stripHTML($('message').val()) == '') {
     alert('Please enter Message.');
}

Hope it will work as good as worked for me.

Have fun

a√萤火虫的光℡ 2024-10-01 17:42:00

这可能对某人有用

var EditorInstance = FCKeditorAPI.GetInstance('JobShortDescription');

alert(EditorInstance.GetHTML());

资源是 http://docs.cksource.com/FCKeditor_2.x /Developers_Guide/JavaScript_API

this may be useful for someone

var EditorInstance = FCKeditorAPI.GetInstance('JobShortDescription');

alert(EditorInstance.GetHTML());

resource is http://docs.cksource.com/FCKeditor_2.x/Developers_Guide/JavaScript_API

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