Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/393.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用下划线隐藏div,不使用脚本模板_Javascript_Jquery_Html_Underscore.js_Underscore.js Templating - Fatal编程技术网

Javascript 使用下划线隐藏div,不使用脚本模板

Javascript 使用下划线隐藏div,不使用脚本模板,javascript,jquery,html,underscore.js,underscore.js-templating,Javascript,Jquery,Html,Underscore.js,Underscore.js Templating,我想使用下划线隐藏div而不是脚本模板,即,而不是: <script type="text/template" id="fooTemplate"> <h2><%= title %></h2> <p> <img src='<%= img %>' width='95' height='150'> <br/><br/> by <

我想使用下划线隐藏div而不是脚本模板,即,而不是:

<script type="text/template" id="fooTemplate">
    <h2><%= title %></h2>
    <p>
        <img src='<%= img %>' width='95' height='150'>
        <br/><br/>
        by <strong><%= autor %></strong>
        <br/><br/>
        <i><%= date %></i>
        <br/><br/>
        <%= description %>
    </p>
 </script>
使用以下命令:

 <div id="fooTemplate" style="display:none">
    <h2><%= title %></h2>
    <p>
        <img src='<%= img %>' width='95' height='150'>
        <br/><br/>
        by <strong><%= autor %></strong>
        <br/><br/>
        <i><%= date %></i>
        <br/><br/>
        <%= description %>
    </p>
 </div>
如果我得到变量并使用html或.text,我会得到以下结果并出现以下问题:

.html

.文本

对于.text html,我丢失了变量的值,但打印变量的值,而html没有捕捉到打印值的语法​​强调我解决了一个替换问题,如下所示:

$("#fooTemplate").html().replace(/&lt;/g, "<").replace(/&gt;/g, ">");

是否有其他解决方案,或者以其他形式将隐藏部分作为下划线模板收费?

出于好奇,为什么不使用脚本模板…?我想要干净的代码,只有html、js和css文件。负责tmpl文件的列行的模板。但在这种情况下,显示的是插入或修改,并带有带有spring消息的标签;此外,浏览器将试图加载您的日志,并用无用的废话污染您的服务器日志。如果你想要干净的代码,那么在服务器上编译你的下划线模板,并将它们作为一堆JavaScript函数发送到浏览器。我将尝试从服务器发送模板。非常感谢你。
<%= title %>

    by <%= autor %>

    <%= date %>

    <%= description %>
$("#fooTemplate").html().replace(/&lt;/g, "<").replace(/&gt;/g, ">");