JQuery's method for reading and setting KindEditor values

Source: Internet
Author: User

When using Kindeditor, you want to use Ajax to pass values, but the method encapsulated by editor does not work because the editor is placed on another jsp page and loaded through iframe, at the same time, the iframe's display = "none" should be triggered through an event.

Copy codeThe Code is as follows:
<Iframe src = "../common/editor. jsp" frameborder = "0" scrolling = "no" style = "margin: 0"
Width = "100%" height = "300" name = "zwFrame" id = "zwFrameId"> </iframe>

Since the original method does not work, I have to get it through jQuery. First of all, I want to read the content in "textarea", that is, contents (~~editor~#.html (), but this cannot be obtained. So I want to get the final result through obtaining the content in iframe, but I have not obtained it. Finally, I can view the final result through firefox debug:


From the figure above, we can see that to get the content "today's weather is good", we only need to get the content in the specified body.
Processing process: first obtain the iframe of the outermost layer, use iframe to obtain the iframe of the child element, and enter the layer to retrieve the body. As follows:

Copy codeThe Code is as follows:
Var editorText = ({{frames}'zwframe'{.doc ument). find ("iframe"). contents (). find ("body ");
Var contents = editorText.html ();

Contents (): searches for all child nodes (including text nodes) within the matching element ). If the element is an iframe, search for the document content.

The following provides several methods to obtain the Element Content in iframe:

Copy codeThe Code is as follows:
$ (Document. getElementsByTagName ("iframe" %%%0%.content%%document.body%.html ();


Display the content of the body element in iframe
Copy codeThe Code is as follows:
$ (Document. getElementById ("iframeId" pai.content?#document.body=.html ();

Obtain the content of the textarea element in iframe
Copy codeThe Code is as follows:
$ (Window. frames ["iframeName" cmd.doc ument). find ("# textareaId" cmd.html ();

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.