gpt4 book ai didi

javascript - 在Coffeescript中编写Ajax函数

转载 作者:行者123 更新时间:2023-11-28 00:13:10 25 4
gpt4 key购买 nike

fiddle - http://codepen.io/mikethedj4/pen/BNRdVp

今天我决定学习 Coffeescript 并尝试制作一些函数、处理事件等。

但是今天我收到一个错误,提示“保留字‘函数’”,并且还不知道如何解决它。

原文:

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

最佳答案

$ ->
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()

关于javascript - 在Coffeescript中编写Ajax函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30698409/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com