关于 DOM 元素的 if 条件检查,我的代码中有一个小问题,要求是我不应该允许“BR”标签通过
function testclick(handler) {
var nodeList = handler.childNodes;
for (var item in nodeList) {
if (typeof (nodeList[item].tagName) !== 'undefined') {
if (typeof (nodeList[item].tagName !== 'BR')) {
alert(nodeList[item].tagName);
}
}
}
}
工作中的 Jsfiddle 在这里 http://jsfiddle.net/ganesh_vellanki/agana62d/6/
有人可以建议我哪里出错了
感谢您抽出时间
最佳答案
试试这个:
function testclick(handler) {
var nodeList = handler.childNodes;
for (var item in nodeList) {
var tagName = nodeList[item].tagName !== undefined ? nodeList[item].tagName.toLowerCase() : null;
if (tagName !== null && tagName !== 'br') {
alert(tagName);
}
}
}
关于javascript - 检查 Javascript 中的特定 DOM 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26293073/