gpt4 book ai didi

mootools - 如何使用 Mootools 通过 id 检查元素的存在

转载 作者:行者123 更新时间:2023-12-04 23:09:14 28 4
gpt4 key购买 nike

如何使用 Mootools 通过 id 检查元素的存在

最佳答案

html:

<div id="foo">some content</div>
javascript
var foo = document.id('foo'); // or $ but should be avoided due to conflicts

// if it returns an Element object, it will be truthy.
if (foo) {
// code for when it exists
}
else {
// code for when it does not.
}
顺便说一句,这模仿了 document.getElementById 的返回值的行为。这是 Vanilla js。对于任何旨在返回单个元素的选择器,它都可以是真的,例如 document.getElement('div.login > a.active') - 不需要仅凭身份证。

关于mootools - 如何使用 Mootools 通过 id 检查元素的存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4654928/

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