【发布时间】:2010-01-19 18:43:34
【问题描述】:
给定以下字符串:
htmlStr1 = "<img>test1</img>";
htmlStr2 = "<div>test2</div>";
我想知道是否有办法编写一个函数来检测“img”标签(例如)。因此,如果将这两个字符串都传递给它,并且如果将第二个字符串传递给它,它就不应该做任何事情。
例如,您将运行如下函数:
result1 = checkIfTagExists(htmlStr1, "img");
result2 = checkIfTagExists(htmlStr2, "img");
alert(result1); // should output "true" or "1" or whatever
alert(result2); // should output "false" or do nothing
【问题讨论】:
标签: javascript jquery html tags