1

CKeditor Element1的外层html如下:

<element1 id="s1">
<mytag>Test1</mytag>
<span> </span>
Some text
<mytag>Test</mytag>
<span> </span>
<mytag>Test3</mytag>
some text
<span> </span>
</element>

var element1=EditorIns.document.getById("s1");
EditorIns.focus();
var mt=element1.getElementsByTag("mytag");
alert(mt.count());

通常它工作正常,但有时mt.count()为 0。

我也尝试过这样的jQuery:

$(element1.$).find("mytag").length;

它也有同样的问题。请帮我解决这个问题

4

2 回答 2

1
Write the code in a function And call this function same as following :-

<script type="text/javascript">
function testElement(){
var element1=EditorIns.document.getById("s1");
EditorIns.focus();
var mt=element1.getElementsByTag("mytag");
alert(mt.count());
}


window.onload=testElement;

</script>

The element is loading after complete the page load and window.onload will call when all the elements completely loaded on the page.
于 2014-03-03T12:20:35.510 回答
0

或者

$(element1).find("mytag").length;

ifelement1是一个普通的 html 元素

于 2013-09-13T10:38:29.933 回答