无法获得更新的textarea值

时间:2022-10-08 07:40:57

I have a problem:

我有个问题:

I have a textarea on my page that looks like this:

我的页面上有一个textarea,如下所示:

<textarea id='redactor_content' name='redactor_content' style='width: 720px; height: 320px;'>$news[3]</textarea>

Where $news[3] is a php variable that I get from MySQL. redactor_content is a WYSIWYG editor where I edit the content of $news[3]. After the content is edited, I want to pass it to mysql to update the table with the following JavaScript:

其中$ news [3]是我从MySQL获得的php变量。 redactor_content是一个WYSIWYG编辑器,我编辑$ news的内容[3]。编辑内容后,我想将其传递给mysql以使用以下JavaScript更新表:

function update_news(n_id) {
    var title = $('#title').val();
    var news_body = $('#redactor_content').val();
    alert(news_body);
    $.post(
        "update.php",
        {n_id: n_id, title: title, body: news_body},
        "html"
    )};

There are 2 more variables in JS which are n_id and title. Both are working OK. But when the alert pops up with the news_body variable I see the old version of textarea (which was initially in the $news[3] variable), not the new, updated one.

JS中还有两个变量是n_id和title。两者都工作正常。但是当使用news_body变量弹出警报时,我会看到旧版本的textarea(最初位于$ news [3]变量中),而不是新版本的更新版本。

I'm stuck guys. Any help is appreciated!

我被困了。任何帮助表示赞赏!

3 个解决方案

#1


2  

most of the wysiwyg editors create a new separate section on the page (an iframe usually) that overlays the textarea they're replacing. You'd need to tell the editor to copy the data in the "fancy" graphical version back to the original form fields so your JS can get the updated version. or figure out how/where the editor is storing the overlayed version so you can grab it from there.

大多数所见即所得的编辑器在页面上创建一个新的单独部分(通常是iframe),它覆盖了他们正在替换的文本区域。您需要告诉编辑器将“花哨”图形版本中的数据复制回原始表单字段,以便您的JS可以获得更新版本。或弄清楚编辑器如何/在哪里存储叠加版本,以便您可以从那里抓取它。

#2


0  

There is probably some client side functionality that the redactor_content exposes to allow you to retrieve the value correctly. Something like $('#redactor_content')[0].getTextValue() or something.

可能有一些客户端功能,redactor_content公开,允许您正确检索值。像$('#redactor_content')[0] .getTextValue()之类的东西。

That isn't the actual code mind you, just an example of how it possible works.

这不是真正的代码,只关注它是如何工作的一个例子。

#3


0  

Thanks for the help guys, the answer to my question is :

感谢帮助人员,我的问题的答案是:

need to replace this line :

需要更换此行:

var news_body = $('#redactor_content').val();

with this line :

用这一行:

var news_body = $('#redactor_content').elrte('val');

#1


2  

most of the wysiwyg editors create a new separate section on the page (an iframe usually) that overlays the textarea they're replacing. You'd need to tell the editor to copy the data in the "fancy" graphical version back to the original form fields so your JS can get the updated version. or figure out how/where the editor is storing the overlayed version so you can grab it from there.

大多数所见即所得的编辑器在页面上创建一个新的单独部分(通常是iframe),它覆盖了他们正在替换的文本区域。您需要告诉编辑器将“花哨”图形版本中的数据复制回原始表单字段,以便您的JS可以获得更新版本。或弄清楚编辑器如何/在哪里存储叠加版本,以便您可以从那里抓取它。

#2


0  

There is probably some client side functionality that the redactor_content exposes to allow you to retrieve the value correctly. Something like $('#redactor_content')[0].getTextValue() or something.

可能有一些客户端功能,redactor_content公开,允许您正确检索值。像$('#redactor_content')[0] .getTextValue()之类的东西。

That isn't the actual code mind you, just an example of how it possible works.

这不是真正的代码,只关注它是如何工作的一个例子。

#3


0  

Thanks for the help guys, the answer to my question is :

感谢帮助人员,我的问题的答案是:

need to replace this line :

需要更换此行:

var news_body = $('#redactor_content').val();

with this line :

用这一行:

var news_body = $('#redactor_content').elrte('val');