Jquery 收藏夹按钮的产品



我希望能够使用 jquery 单击功能将我的字体 awsome 图标发送到网络方法我的问题是该图标将具有多种图像,其形式为iconFavourites_productcode产品代码是 alaphnumeric id,用于标识客户想要喜欢的产品代码。

这是 asp.net 平台中 vb.net 应用程序。

$('i.button').click(function(){
var $this = $(this);
if ($this.hasClass('fa-heart-o')) {
$this.removeClass('fa-heart-o');
$this.addClass('fa-heart');
} else {
$this.removeClass('fa-heart');
$this.addClass('fa-heart-o');
}
});

我不,我可以使用上述内容来更改图标,但我只想在将图标添加到数据库时将其更改为红色,而在未将其添加到数据库时将其更改为黑色。我以为我会有一些网络方法,比如

[WebMethod]
Function FaveProduct(productId As String,ActiveState as int)
End Function

我的问题是我将如何使用帖子将我的按钮单击发送到网络方法,我可以为此使用 jquery,但不确定如何或以最佳方式将处于活动状态的活动发送到我的函数。我在想活动状态 1 添加了 2 删除。谁能告诉我如何在jquery帖子中对此进行编码?

我也不需要如何从我正在使用的图标的名称部分 sep id。

你可以直接通过jQuery和CSS来做到这一点。 添加名为 fav_color 的新类

<style>
.fav_color{
color:red;
}
</style>

现在使用 jQuery 添加此类。

$this.addClass('fav_color');

或将其删除

$this.removeClass('fav_color');

最新更新