gpt4 book ai didi

jQuery 如何控制文档中是否存在某个元素?

转载 作者:行者123 更新时间:2023-12-01 01:55:32 26 4
gpt4 key购买 nike

我想在页面加载时控制文档中是否存在元素及其 ID。我尝试了下面的代码,但失败了。

   if($(':not(#<%=TextBox1.ClientID %>)')){
alert("Object is null")else{alert("Object is exist")}}

感谢您现在的帮助。

最佳答案

阅读这篇文章(由 jakemcgraw 提供):

Is there an "exists" function for jQuery?

jQuery.fn.exists = function(){return jQuery(this).length>0;}

if ($('#<%=TextBox1.ClientID %>').exists()) {
// Do something
}

关于jQuery 如何控制文档中是否存在某个元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1654495/

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