摘要:
下文讲述使用javascript代码判断id是否存在于网页中的方法分享,如下所示;
实现思路:
使用document.getElementById("对象id");
对对象id进行检测,
当返回值为非Null时,则表示id存在于网页
例:
javascript中检测id是否存在于网页的示例分享
maomao365.com
javascript id是否存在于网页中的示例分享
window.onload = function (){
var d = document.getElementById("divTest");
var txtValue = document.getElementById("txt");
var b = document.getElementById("btn");
b.onclick = function(){
t = txtValue.value;
if(document.getElementById(t))
{
d.innerHTML =t+"存在于网页中";
}else
{
d.innerHTML =t+"不存在于网页中";
}
}
}
id名称:
id="txt" value="btn" />
测试

最后
以上就是寂寞烤鸡最近收集整理的关于javascript判断html是否存在,javascript 如何判断一个id是否存在于html网页中呢?的全部内容,更多相关javascript判断html是否存在,javascript内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复