Jquery收藏夹产品按钮

时间:2017-08-28 08:24:41

标签: jquery asp.net vb.net

我希望能够使用jquery点击功能将我的字体awsome图标发送到web方法我的问题是图标将以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

我的问题是我如何使用帖子发送我的按钮点击webmethod我可以使用jquery,但不知道如何或最好的方式将活动状态发送到我的功能。我在想ActiveState 1添加2删除。任何人都可以告诉我如何在jquery帖子中编写代码吗?

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

1 个答案:

答案 0 :(得分:0)

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

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

现在使用jQuery添加此类。

$this.addClass('fav_color');

或删除它

$this.removeClass('fav_color');