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;
它也有同样的问题。请帮我解决这个问题
答案 0 :(得分: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.
答案 1 :(得分:0)
或
$(element1).find("mytag").length;
如果element1
是常规html元素