Node.innerHTML以小写形式提供标签名称 [英] Node.innerHTML giving tag names in lower case

查看:198
本文介绍了Node.innerHTML以小写形式提供标签名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在迭代 NodeList 以获取 Node 数据,但是使用 Node.innerHTML 时,我会以小写形式获取标签名称。 p>

实际标签

 <面板> <标签>试验< /标签>< /面板> 

作为

 <面板><标签>试验< /标签>< /面板> 

我需要这些标签。是否可以用正则表达式得到它?我正在使用dojo(在dojo中有什么办法吗?)

  var xhrArgs = {
url: ./user/\"+Runtime.userName+\"/ws/workspace/\"+Workbench.getProject()+\"/lib/custom/\"+(first.type).replace(\".\",\"/\")+ 。$
内容:{},
sync:true,
load:function(data){
var test = domConstruct.toDom(data);
dojo.forEach(dojo.query([id],test),function(node){
domAttr.remove(node,id);
});
var childEle =;
dojo.forEach(test.childNodes,function(node){
if(node.innerHTML){
childEle + = node.innerHTML;
}
});
command.add(new ModifyCommand(newWidget,{},childEle,context));
}
};


解决方案

你不能指望。 innerHTML 保留原始HTML的确切性质。实际上,在某些浏览器中,它有很大的不同(尽管产生相同的结果),具有不同的引号,大小写,属性顺序等等。



不依赖于案例的保存和调整您的JavaScript来处理不确定的情况。



当然可以使用正则表达式来进行不区分大小写的搜索( i标志将其搜索指定为不区分大小写),但通常使用直接DOM访问/搜索而不是innerHTML搜索更好。在我们可以提供一些代码之前,您需要再详细说明一下您要做什么。


I am iterating NodeList to get Node data, but while using Node.innerHTML i am getting the tag names in lowercase.

Actual Tags

<Panel><Label>test</Label></Panel>

giving as

<panel><label>test</label></panel>

I need these tags as it is. Is it possible to get it with regular expression? I am using it with dojo (is there any way in dojo?).

var xhrArgs = {
            url: "./user/"+Runtime.userName+"/ws/workspace/"+Workbench.getProject()+"/lib/custom/"+(first.type).replace(".","/")+".html",
            content: {},
            sync:true,
            load: function(data){
                var test = domConstruct.toDom(data);
                dojo.forEach(dojo.query("[id]",test),function(node){
                    domAttr.remove(node,"id");
                });
                var childEle = "";
                dojo.forEach(test.childNodes,function(node){
                    if(node.innerHTML){
                            childEle+=node.innerHTML;
                    }
                });
                command.add(new ModifyCommand(newWidget,{},childEle,context));
            }
    };

解决方案

You cannot count on .innerHTML preserving the exact nature of your original HTML. In fact, in some browsers, it's significantly different (though generates the same results) with different quotation, case, order of attributes, etc...

It is much better to not rely on the preservation of case and adjust your javascript to deal with uncertain case.

It is certainly possible to use a regular expression to do a case insensitive search (the "i" flag designates its searches as case insensitive), though it is generally much, much better to use direct DOM access/searching rather than innerHTML searching. You'd have to tell us more about what exactly you're trying to do before we could offer some code.

这篇关于Node.innerHTML以小写形式提供标签名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆