gpt4 book ai didi

javascript - jquery代码问题,有合适的格式吗?

转载 作者:行者123 更新时间:2023-12-03 03:43:17 25 4
gpt4 key购买 nike

我的 .js 文件中有这段代码,自从添加它以来,其他一些 Jquery 功能就停止工作了。问题是怎么写的?谢谢!

$(window).load ->
$('a[data-target]').click (e) ->
e.preventDefault()
$this = $(this)
if $this.data('target') == 'Add to'
url = $this.data('addurl')
new_target = "Remove from"
else
url = $this.data('removeurl')
new_target = "Add to"
$.ajax url: url, type: 'put', success: (data) ->
$('.cart-count').html(data)
$this.find('span').html(new_target)
$this.data('target', new_target)

$(window).load ->
$('#mycart .fi-x').click (e) ->
e.preventDefault()
$this = $(this).closest('a')
url = $this.data('targeturl')
$.ajax url: url, type: 'put', success: (data) ->
$('.cart-count').html(data)
$this.closest('.cart-movie').slideUp()

最佳答案

那就是 coffeescript ,您可能需要将其转换为 javascript:

$(window).load(function() {
return $('a[data-target]').click(function(e) {
var $this, new_target, url;
e.preventDefault();
$this = $(this);
if ($this.data('target') === 'Add to') {
url = $this.data('addurl');
new_target = "Remove from";
} else {
url = $this.data('removeurl');
new_target = "Add to";
}
return $.ajax({
url: url,
type: 'put',
success: function(data) {
$('.cart-count').html(data);
$this.find('span').html(new_target);
return $this.data('target', new_target);
}
});
});
});

$(window).load(function() {
return $('#mycart .fi-x').click(function(e) {
var $this, url;
e.preventDefault();
$this = $(this).closest('a');
url = $this.data('targeturl');
return $.ajax({
url: url,
type: 'put',
success: function(data) {
$('.cart-count').html(data);
return $this.closest('.cart-movie').slideUp();
}
});
});
});

关于javascript - jquery代码问题,有合适的格式吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45521569/

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