jquery怎么判断id是否存在


当前第2页 返回上一页

1

2

3

4

5

6

7

8

9

10

11

12

13

if ($('#myElement').length > 0) {

    // 存在

    document.write("id 为 myElement 元素存在");

} else {

    document.write("id 为 myElement 元素不存在");

}

document.write("<br>");

if ($('#xxx').length > 0) {

    // 存在

    document.write("id 为 xxx 元素存在");

} else {

    document.write("id 为 xxx 元素不存在");

}

结果:

1

2

id 为 myElement 元素存在

id 为 xxx 元素不存在

相关推荐:js教程

以上就是jquery怎么判断id是否存在的详细内容,更多文章请关注木庄网络博客

返回前面的内容

相关阅读 >>

jQuery中$("#")和$("#"+xx)的区别

jQuery怎么添加css

jQuery怎么转数字

jQuery判断是否为ie浏览器的方法

jQuery怎么处理事件的

html5和jQuery实现弹出创意搜索框层的方法

jQuery中怎样实现两秒之后刷新页面

javascript中stop方法的作用是什么

jQuery中on()和live()的区别是什么?

怎么解决jQuery ajax失败问题

更多相关阅读请进入《jQuery》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...