在浏览器中保留属性的单引号或双引号 [英] Preserving single or double quotes around attributes in browser

查看:294
本文介绍了在浏览器中保留属性的单引号或双引号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望保留html属性的单引号或双引号,特别是内容可编辑div中的innerHTML。我知道这是一个奇怪的要求,但我正在寻找可能性。因此,可以说我把HTML放在了服务器的内容可编辑div中:

 < div class =editable> 
按下按钮< img src ='BUTTON_BACK.png'vspace =' - 16'width = '32'height =32>
< / div>

这应该被保留。但目前在Firefox中,当我检查DOM时,它只是将所有单引号转换为所有属性的双引号。



所以问题是:


  • 是否有任何浏览器配置可以禁用此功能行为?

  • DTD如何在这种情况下有所帮助(仅适用于可编辑的部分)?

  • 任何其他的景点?



  • 编辑:
    另外,当我通过innerHTML获得div的内容时,我得到其内容的修改版本,单引号替换为双引号。作为每个SGML ,并没有这样的要求使用双引号引用属性。所以它不仅仅是开发者工具。



    我已经访问过SOQ 1 2 ,但我的问题略有不同。

    解决方案

    HTML是结构化信息的运营商,它本身不是信息。这就像信件周围的信封。 HTML用于将所需DOM的结构信息从服务器传送到浏览器。一旦浏览器收到这些信息,它就会解包它并构建DOM。然后它丢弃HTML文本,因为它没有进一步的用途;它现在正在使用DOM数据结构。



    DOM中没有存储用于构建DOM元素属性的引号的地方。因为它不相关。 foo ='bar'与100%等价于 foo =bar foo = bar ,以表达属性及其序列化形式的值。始终可以从DOM派生序列化表单;换句话说,DOM总是可以从头开始再次写入HTML。您可以整天转换HTML→DOM→HTML→DOM→HTML。但是,HTML的特定格式不会粘连,因为它无关紧要并在转换中被丢弃。



    这就是你所看到的在DOM检查器中或在 .innerHTML 中:仅表示以序列化HTML表示的当前DOM。只要它表达相同的信息,关心HTML的具体格式就毫无意义。不,你不能保存它。



    如果你真的想要这样做,你必须向后弯曲,并做大量的手动HTML处理。 / p>

    I want to preserve single or double quotes around html attributes, specifically for innerHTML within the content editable div. I know this is weird requirement, but I am looking for possibilities. So lets say I put html in content editable div from server :

    <div class="editable">
        PRESS MENU BUTTON<img src='BUTTON_BACK.png' vspace='-16' width='32' height="32">
    </div>
    

    This should be preserved. But currently in firefox, as I inspect the DOM it just converts all single quotes to double quotes around all attributes.

    So the question is :

    • Is there any browser configurations to disable this behavior ?
    • How can DTD be helpful in this scenario (applicable to only editable section)?
    • Any other in-sights ?

    Edit: Also when I get the contents of div by innerHTML I get the modified version of its contents , single quotes replaced by double quotes . As per SGML there is not such requirement to quote attributes using double quotes.So its not only the developer tools only .

    I have already visited SOQs 1, 2,but my question is slightly different.

    解决方案

    HTML is a "carrier of structured information", it itself is not the information. It's like the envelope around a letter. HTML is used to convey the structural information of the desired DOM from your server to the browser. Once the browser receives this information, it "unpacks" it and constructs the DOM. Then it discards the HTML text, because it has no further use for it; it is now working with the DOM data structure.

    There's no place in the DOM for storing what kind of quotes were used to construct a DOM element's attributes. Because it's irrelevant. foo='bar' is 100% equivalent to foo="bar" to foo=bar in terms of expressing an attribute and its value in serialised form. It's always possible to derive a serialised form from the DOM; in other words the DOM can always be written to HTML again from scratch. You can convert HTML → DOM → HTML → DOM → HTML back and forth all day long. However, the specific formatting of the HTML will not stick, because it's irrelevant and gets discarded in the conversion.

    That's what you're seeing in the DOM inspector or in .innerHTML: just a representation of the current DOM expressed in serialised HTML. There's no point in caring about the specific format of that HTML, as long as it expresses the same information. And no, you can't preserve it.

    If you really really want that, you'll have to bend over backwards and do a lot of manual HTML processing.

    这篇关于在浏览器中保留属性的单引号或双引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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