“//” …“ //]]>” appears on the page when “ //<![CDATA[ ” …“//]]>” are used to wrap a JS code

依然范特西╮ 提交于 2019-12-13 07:57:13

问题


I'm trying to add the html5 drag 'n drop upload file on my JSF web page so i had to add this script into it

<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>

if i take out the cdata tag which is around my script i get this error :

The value of attribute "data-bind" associated with an element type "span" must not contain the '<' character.


回答1:


The script you've posted is a text/html script which acts as a template in knockout. That id is required for knockout to reference the template.

As for the CDATA sections, unless you're using XML you can take them out.



来源:https://stackoverflow.com/questions/19860518/appears-on-the-page-when-cdata-are-us

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!