0

我正在使用 Dmxzones Advanced HTML Editor 3,它插入以下代码:

<textarea id="advHTMLEdit1" name="advHTMLEdit1" class="dmxEditor" style="width:700px;height:300px"></textarea>

 jQuery(document).ready(
   function()
     {
       jQuery("#advHTMLEdit1").dmxEditor(
         {"width": 700, "lineBreak": "p", "allowUpload": true, "uploadPath": "tmp", "subFolder": "1", "uploadProcessor": "php", "allowResize": true, "includeCss": "tutorial.css", "skin": "blue"
       );
     }
 );

它使用 javascript execCommand() 插入元素,并将类样式应用于这些元素。

和:jQuery("#advHTMLEdit1")[0]

我似乎能够访问它,但我尝试过的任何东西都没有让我访问 childNodes。我希望能够遍历编辑器创建的每个 childNode,查询类,如果它是特定的 className,则替换该元素上的 HTML。

我不使用 jQuery,虽然我自己尝试了很多事情,但我似乎无法访问编辑器创建的任何这些元素。

4

1 回答 1

1

从这个答案中借用一点,并根据您提供的链接,您应该执行以下操作:

如果要css对所有匹配的类应用一致:

var ifrm = $("#advHTMLEdit1").prev(".dmx-editor-frame-wrapper").find("iframe")[0];
ifrm = (ifrm.contentWindow) ? ifrm.contentWindow : (ifrm.contentDocument.document) ? ifrm.contentDocument.document : ifrm.contentDocument;
ifrm = $(ifrm.document);
ifrm.find(".yourClass").css("cssProperty", "cssValue");

如果要css对所有元素应用不同的:

var ifrm = $("#advHTMLEdit1").prev(".dmx-editor-frame-wrapper").find("iframe")[0];
ifrm = (ifrm.contentWindow) ? ifrm.contentWindow : (ifrm.contentDocument.document) ? ifrm.contentDocument.document : ifrm.contentDocument;
ifrm = $(ifrm.document);
var elem;
ifrm.find("body *").each(function(){
    elem = $(this);        
    if(elem.hasClass("yourClass") && elem.is("span")) {
        //elem.css("cssProperty", "cssValue");                
        elem.text("new text");
    }
});

如果要更改具有特定类的所有跨度的文本,可以使用更短的代码执行以下操作,无需循环:

ifrm.find("span.myClass").text("new text");

span仅当 的新文本取决于名称时才使用第二个示例class

编辑: 根据您在页面中提供的示例,您可以编写:

ifrm.find("p.codeblock").text("new text");
于 2012-06-14T11:44:29.990 回答