如何卸下按钮并将其替换为<;a>;通过jquery标记

如何卸下按钮并将其替换为<;a>;通过jquery标记,jquery,Jquery,这是我的JQuery代码 <script> $(".simpleCart_shelfItem button").click(function() { $(this).prop('disabled', true); $(this).addClass('disabled'); $(this).html("Adding &nbsp;&nbsp;<i class='icon-spinner9 spin'>&l

这是我的JQuery代码

<script>
$(".simpleCart_shelfItem button").click(function()
    {
        $(this).prop('disabled', true);
        $(this).addClass('disabled');
        $(this).html("Adding &nbsp;&nbsp;<i class='icon-spinner9 spin'></i>");

        var action = "add";
        var queryString = "action="+action+"&pid="+this.value;
        var $this = $(this);

        $.ajax({
                url: "add_cart",
                data: queryString,
                type: "POST",
                success:function(data)
                    {
                        $this.remove();
                        $($this).before("<a href='cart' class='btn view-more'>In Your Cart (View)</a>");
                    },
                error:function(){}
            });
    });
</script>

$(“.simpleCart_shelfItem按钮”)。单击(函数()
{
$(this.prop('disabled',true);
$(this.addClass('disabled');
$(this.html(“添加”);
var action=“添加”;
var queryString=“action=“+action+”&pid=“+this.value;
var$this=$(this);
$.ajax({
url:“添加购物车”,
数据:查询字符串,
类型:“POST”,
成功:功能(数据)
{
$this.remove();
$($this.),在(“”)之前;
},
错误:函数(){}
});
});
这是我的HTML代码:

<div class="simpleCart_shelfItem">
    <p><span>&#8377; price</span> <i class="item_price">&#8377; selling price</i></p>
    <button value="some value" class="btn view-more">Add To Cart</button>
    <a href="product?id=id>
        <button class="hashs-cart">Buy Now</button>
    </a>
</div>

₹;价格₹;售价

添加到购物车
我想要实现的是,只要用户单击add to cart(添加到购物车),按钮就会被删除并替换为此=>

通过使用上面的JQuery代码,我可以删除按钮,但不能用
标记替换它

有人能帮忙吗?为什么会这样

 $($this).before 
应该是
$this.replacewith

 <script>
$(".simpleCart_shelfItem button").click(function()
{
    $(this).prop('disabled', true);
    $(this).addClass('disabled');
    $(this).html("Adding &nbsp;&nbsp;<i class='icon-spinner9 spin'></i>");

    var action = "add";
    var queryString = "action="+action+"&pid="+this.value;
    var $this = $(this);

    $.ajax({
            url: "add_cart",
            data: queryString,
            type: "POST",
            success:function(data)
                {
                   /*$this.remove();*/   //remove this line
                    $this.replacewith("<a href='cart' class='btn view-more'>In Your Cart (View)</a>");
                },
            error:function(){}
        });
});

$(“.simpleCart_shelfItem按钮”)。单击(函数()
{
$(this.prop('disabled',true);
$(this.addClass('disabled');
$(this.html(“添加”);
var action=“添加”;
var queryString=“action=“+action+”&pid=“+this.value;
var$this=$(this);
$.ajax({
url:“添加购物车”,
数据:查询字符串,
类型:“POST”,
成功:功能(数据)
{
/*$this.remove();*///删除此行
$this。替换为(“”);
},
错误:函数(){}
});
});

AAAA如果我将其从购物车中移除:D
$this
已经是一个
$(this)
,因此不需要
$($this)
-只需使用
$this
。是否清楚?如果删除$this.remove()的意思是。然后不能使用$(this)来添加使用$(this)的元素。因为它不再使用
$this.replaceWith('your code here')
@eventherdude你的代码为我工作。太棒了!