gpt4 book ai didi

javascript - Element.getElementByTag ("mytag")有时返回空

转载 作者:行者123 更新时间:2023-11-28 01:58:15 26 4
gpt4 key购买 nike

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;

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

最佳答案

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.

关于javascript - Element.getElementByTag ("mytag")有时返回空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18784160/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com