使用jquery获取文本编辑器值

时间:2011-10-04 10:05:17

标签: php jquery html5 fckeditor

我有一个短信,我想使用jquery将其内容提交到php文件。

我的索引文件是:

<!--  jquery core -->
<script src="js/jquery-1.4.1.min.js" type="text/javascript"></script>
<!-- FCK editor Starts -->
<script src="texteditor/nicEdit.js" type="text/javascript"></script>
<script type="text/javascript">
bkLib.onDomLoaded(function() {
    new nicEditor({fullPanel : true}).panelInstance('area2');
});
</script>
<!-- FCK editor End -->
<script>
$(document).ready(function(){
    $("form#submit").submit(function() {
    // we want to store the values from the form input box, then send via ajax below
    var area2     = $('#area2').attr('value');
    var pageName     = $('#pageName').attr('value');
        $.ajax({
            type: "POST",
            url: "ajax.php",
            data: "pageName="+ pageName +"& textarea="+ area2,
            success: function(){
                $('form#submit').hide(function(){$('div.success').fadeIn();});

            }
        });
    return false;
    });
});
</script>
<div class="container">
<form id="submit" method="post">
        <textarea id="area2" name="area2" class="di"><div id="responsecontainer"></div></textarea>
        <input type="text" id="pageName" name="pageName" value="home" />
        <button>Submit</button>
    </form>
    <div class="success" style="display: none;">Client has been added.</div>
</div>

我的ajax.php文件是:

<?php
$pgName = $_POST['pageName'];
    $content = $_POST['textarea'];
    $content = str_replace('<div id="responsecontainer">','',$content);
    $content = str_replace("</div>",'',$content);

    $fp=fopen($pgName.'.html','w+');
    fwrite($fp,$content);
    fclose($fp);
?>

它适用于textarea和textbox但不能获取FCK texteditor内容。

1 个答案:

答案 0 :(得分:1)

尝试以下方法:

var area2 = $('#submit .nicEdit-main').html();