admin管理员组文章数量:1391937
I am trying to use Coffeescript, but I am having a problem on my web application. Its methods are not called until I reload the page.
I think that what is missing is the $(document).ready(function () {
part, but I couldn't find how to do it in the web.
file_name.js (works great)
$(document).ready(function () {
$(document).on('click', '.add_fields', function(event) {
event.preventDefault();
/* Act on the event */
time = new Date().getTime()
regexp = new RegExp($(this).data('id'), 'g')
$(this).before($(this).data('fields').replace(regexp, time))
});
});
file_name.coffee (doesn't work)
jQuery ->
$('form').on 'click', '.add_fields', (event) ->
time = new Date().getTime()
regexp = new RegExp($(this).data('id'), 'g')
$(this).before($(this).data('fields').replace(regexp, time))
event.preventDefault()
How can I fix this?
I am trying to use Coffeescript, but I am having a problem on my web application. Its methods are not called until I reload the page.
I think that what is missing is the $(document).ready(function () {
part, but I couldn't find how to do it in the web.
file_name.js (works great)
$(document).ready(function () {
$(document).on('click', '.add_fields', function(event) {
event.preventDefault();
/* Act on the event */
time = new Date().getTime()
regexp = new RegExp($(this).data('id'), 'g')
$(this).before($(this).data('fields').replace(regexp, time))
});
});
file_name.coffee (doesn't work)
jQuery ->
$('form').on 'click', '.add_fields', (event) ->
time = new Date().getTime()
regexp = new RegExp($(this).data('id'), 'g')
$(this).before($(this).data('fields').replace(regexp, time))
event.preventDefault()
How can I fix this?
Share Improve this question asked May 20, 2018 at 1:09 Augusto CarmoAugusto Carmo 4,9642 gold badges37 silver badges79 bronze badges 1-
1
Coffeescript is just fancy Javascript. "On document ready" is not a feature of Javascript language, but feature of the browser or jQuery library. So, when in doubt, just write same Javascript code with block indentation instead of curly brackets, and replacing
function()
with->
– metalim Commented Jun 6, 2018 at 19:53
1 Answer
Reset to default 6$(document).ready ->
See example at https://github./jashkenas/coffeescript/blob/master/documentation/site/docs.coffee#L16
本文标签: javascriptCoffeescript equivalent to On Document ReadyStack Overflow
版权声明:本文标题:javascript - Coffeescript equivalent to On Document Ready - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744679202a2619295.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论