我安装了“Mindscape Web Workbench”visual studio扩展,并添加了来自Nuget的LessCoffee参考。
在我的页面中,我编写了这些代码并且它正在运行。
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
<script src="http://jashkenas.github.com/coffee-script/extras/coffee-script.js" type="text/javascript"></script>
<script type="text/coffeescript">
@fonksiyon = () -> alert "I knew it!"
@myalert=(myText)-> alert myText
</script>
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<input type="button" id="deneme" onclick="fonksiyon()" value="Deneme" />
<br />
<input type="button" id="Button1" onclick="myalert('yazi veya uyari')" value="Deneme" /> </asp:Content>
我想从“Coffee1.coffee”运行相同的代码,所以我写了这个:
CoffeeScript.coffee中的
@fonksiyon = () -> alert "I knew it!"
@myalert=(myText)-> alert myText
在Asp.net页面:
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
<script src="http://jashkenas.github.com/coffee-script/extras/coffee-script.js" type="text/javascript"></script>
<script src="CoffeeScript1.coffee" type="text/coffeescript"></script>
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<input type="button" id="deneme" onclick="fonksiyon()" value="Deneme" />
<br />
<input type="button" id="Button1" onclick="myalert('yazi veya uyari')" value="Deneme" />
</asp:Content>
但是这段代码不起作用。
CoffeeLess添加web.config:
<httpHandlers>
<add path="*.coffee" type="DotSmart.CoffeeScriptHandler, LessCoffee" verb="*" validate="false" />
<add path="*.less" type="DotSmart.LessCssHandler, LessCoffee" verb="*" validate="false" />
<add path="*.less.css" type="DotSmart.LessCssHandler, LessCoffee" verb="*" validate="false" />
</httpHandlers>
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<validation validateIntegratedModeConfiguration="false" />
<handlers>
<add path="*.coffee" type="DotSmart.CoffeeScriptHandler, LessCoffee" verb="*" name="DotSmart.CoffeeScriptHandler" />
<add path="*.less" type="DotSmart.LessCssHandler, LessCoffee" verb="*" name="DotSmart.LessCssHandler" />
<add path="*.less.css" type="DotSmart.LessCssHandler, LessCoffee" verb="*" name="DotSmart.LessCssHandler2" />
</handlers>
</system.webServer>
我用Firebug控制它并返回此错误:
'SyntaxError:调用方法时第4行的保留字“function”:[nsIDOMEventListener :: handleEvent]
[打破此错误]
过滤的chrome url chrome://firebug/content/net/spy.js
我该怎么办?
感谢。
答案 0 :(得分:1)
此处的信息可能对您的工作有所帮助。
答案 1 :(得分:0)
如果您使用httpHandler提供* .coffee文件,它们会在服务器上转换为JavaScript,因此您的客户端脚本标记应该实际指定JavaScript:
<script src="CoffeeScript1.coffee" type="text/javascript"></script>