代码之家  ›  专栏  ›  技术社区  ›  Konrad Höffner

JavaScript/HTML复选框内部HTML的显示不一致

  •  -1
  • Konrad Höffner  · 技术社区  · 9 年前

    input2 = document.getElementById("input2");
    input2.innerHTML = "Check me inner HTML";
    input2.innerText = "Check me inner Text";
    
    input3 = document.createRange().createContextualFragment("<input type='checkbox'>Check me fragment</input>");
    document.body.appendChild(input3);
    <input type="checkbox">Check me HTML</input>
    <input type="checkbox" id="input2"></input>
    1 回复  |  直到 9 年前
        1
  •  1
  •   Cerbrus    9 年前

    <input> 元素没有“内部HTML”。生成的HTML结构为:

    <input type="checkbox">Check me HTML
    <input type="checkbox" id="input2">Check me inner Text</input>
    <script type="text/javascript">/* your js */</script>
    <input type="checkbox">Check me fragment
    

    第二个不是有效的HTML。不会呈现“内部”文本。


    (The </input>