【问题标题】:"//" ......" //]]>" appears on the page when " //<![CDATA[ " ....."//]]>" are used to wrap a JS code"//" ......" //]]>" 当" //<![CDATA[ " ....."//]]>" 用于包装JS代码时出现在页面上
【发布时间】:2013-11-20 13:10:50
【问题描述】:

我正在尝试在我的 JSF 网页上添加 html5 拖放上传文件,所以我必须将此脚本添加到其中

<script type="text/html" id="template-uploads">

  //<![CDATA[


      <div data-bind="visible: showTotalProgress()">
            <div>
                <span data-bind="text: uploadSpeedFormatted()"></span>
                <span data-bind="text: timeRemainingFormatted()" style="float: right;"></span>
            </div>
            <div class="uploadimage-totalprogress">
                <div class="uploadimage-totalprogressbar" style="width: 0%;" data-bind="style: { width: totalProgress() + '%' }"></div>
            </div>
        </div>
        <div data-bind="foreach: uploads">
            <div class="uploadimage-upload" data-bind="css: { 'uploadimage-uploadcompleted': uploadCompleted() }">
                <div class="uploadimage-fileinfo">
                    <strong data-bind="text: fileName"></strong>
                    <span data-bind="text: fileSizeFormated"></span>
                    <span class="uploadimage-progresspct" data-bind="visible: uploadProgress() < 100"><span data-bind="text: uploadSpeedFormatted()"></span></span>
                </div>
                <div class="uploadimage-progress">
                    <div class="uploadimage-progressbar" style="width: 0%;" data-bind="style: { width: uploadProgress() + '%' }"></div>
                </div>
            </div>
        </div>

    //]]>
    </script>

如果我取出脚本周围的 cdata 标签,我会收到此错误:

与元素类型关联的属性“data-bind”的值 “span”不能包含“

【问题讨论】:

  • 您的问题的标题似乎描述的问题与您所说的不同。
  • 我在这里没有看到任何 JavaScript
  • Roman : 我编辑了我的帖子。
  • 门把手:确实,你是对的。它有点像一个模板,但它会产生与 JS 中的“

标签: jsf knockout.js


【解决方案1】:

您发布的脚本是一个 text/html 脚本,在淘汰赛中充当模板。该 id 是敲除引用模板所必需的。

至于 CDATA 部分,除非您使用 XML,否则您可以将它们取出。

【讨论】:

  • 对不起,我的英语不好,我不确定我是否理解你的回答。你说 id 是必需的(显然当我摆脱它时出现错误)但是你说我可以删除它?
  • 你可以取出//&lt;![CDATA[//]]&gt;
  • 我说当我取出 // jamie 时会发生什么!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-03-28
  • 2021-12-03
  • 2022-06-24
  • 2022-01-13
  • 2017-10-16
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多