如何在js文件中编写JQuery模板

如何在js文件中编写JQuery模板,jquery,asp.net-mvc-3,templates,razor,jquery-templates,Jquery,Asp.net Mvc 3,Templates,Razor,Jquery Templates,我有一些JQuery模板代码是在.cshtml文件中编写的,但我想将其移动到js文件中。但是js文件无法识别 下面是tmpl的示例 << <script type="text/x-jquery-tmpl" id="searchResult"> <li><a href="#" data-name="${Name}">${Name}</a></li> </script> >> > 谢谢。您是否

我有一些JQuery模板代码是在
.cshtml
文件中编写的,但我想将其移动到
js
文件中。但是js文件无法识别

下面是
tmpl
的示例

<<
<script type="text/x-jquery-tmpl" id="searchResult">
    <li><a href="#" data-name="${Name}">${Name}</a></li>
</script>
>>
>

谢谢。

您是否错过了以下声明:

<script src="http://ajax.microsoft.com/ajax/jquery.templates/beta1/jquery.tmpl.min.js"></script>

首先,我建议不要混合使用模板代码和脚本代码,但这是您的设计决定


尝试移除
标签,因为发动机可能会认为它是蛋糕上的蛋糕。脚本中的脚本标记。

lol,您不应该在js文件中包含
标记。Js文件是“假定的”
,但是我不熟悉这里的设置,因为脚本标记之间的内容似乎是非常基本的html,应该放在html文件中。Js通常用于acctual javascript,也称为:

$(function() {
    $(document).find("a").css("text-decoration", "none");
}); //  this is an example of somthing typically found in a js file whereas

// the following would generally be placed as in a .php VIEW file, thus MVC, Modal View Control
<ul>
    <li><a href="#" data-name="${Name}">${Name}</a></li>
</ul>
$(函数(){
$(document.find(“a”).css(“文本装饰”、“无”);
}); //  这是一个典型的js文件中的例子
//以下内容通常放在.php视图文件中,即MVC、模态视图控件中
还要记住,我的示例使用jquery标记,因此它可能无法在普通javascript程序中工作