Javascript 用Coffeescript编写Ajax函数
小提琴- 今天我决定学习咖啡脚本,做一些函数,处理事件等等 然而今天我遇到了一个错误,上面写着“保留字‘函数’”,我还没有找到解决方法 原件:Javascript 用Coffeescript编写Ajax函数,javascript,jquery,ajax,coffeescript,Javascript,Jquery,Ajax,Coffeescript,小提琴- 今天我决定学习咖啡脚本,做一些函数,处理事件等等 然而今天我遇到了一个错误,上面写着“保留字‘函数’”,我还没有找到解决方法 原件: $(function () { function download_to_textbox(url, el) { $.get(url, null, function (data) { el.val(data); }, "text"); } download_to_textbox
$(function () {
function download_to_textbox(url, el) {
$.get(url, null, function (data) {
el.val(data);
}, "text");
}
download_to_textbox("http://code.jquery.com/jquery-latest.min.js", $("textarea"));
});
我的译文:
(($) ->
function download_to_textbox(url, el) {
$.get(url, null, (data) ->
el.val(data);
}, "text");
}
download_to_textbox("http://code.jquery.com/jquery-latest.min.js", $("textarea"));
$("textarea").click ->
$(this).select();
) jQuery
CS中没有
函数
关键字。
$ ->
download_to_textbox = (url, el) ->
$.get url, null, ((data) ->
el.val data
return
), 'text'
download_to_textbox 'http://code.jquery.com/jquery-latest.min.js', $ 'textarea'
$("textarea").click ->
$(this).select()