2011-10-04 102 views
1

我有一個texteditor,我想用jquery將它的內容提交給一個php文件。使用jquery獲取texteditor值

我的索引文件是:

<!-- 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); 
?> 

它工作正常的文本區域和文本框,但不獲取FCK文本編輯內容。

+0

我用VAR面積2 = $( '#提交')查找文本();(」 nicEdit-主。)。那麼它只是發佈文本而不是文本樣式(粗體,顏色,家庭等) –

+0

在textarea(而不是生成的iframe)上的.nicEdit-main或'.val()'上嘗試'.html()'。 – dresende

回答

1

嘗試以下操作:

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