MVC Webshopでショッピングカートを表示するパーシャルビューがありますが、何らかの理由で「ゴミ箱」ボタンをクリックできません。ボタンをクリックしてもボタンが表示されないjqueryファンクション
これは私の現在のコードです。
@model ShoppingCart
@foreach (var product in Model.Items)
{
<li>
<div class="b-cart-table ">
<a href="#" class="image">
<img width="70" height="70" src="@product.ImageUrl" alt="/">
</a>
<div class="caption">
<a class="product-name" href="#">@product.Name</a>
<span class="product-price">@product.Quantity x $ @product.Price.ToString("00.00").Replace(",", ".")</span>
<div class="rating">
<span class="star"><i class="fa fa-star"></i></span>
<span class="star"><i class="fa fa-star"></i></span>
<span class="star"><i class="fa fa-star"></i></span>
<span class="star"><i class="fa fa-star"></i></span>
<span class="star star-empty"><i class="fa fa-star-o"></i></span>
</div>
</div>
<button onclick="remove();" class="btn btn-remove removeitem"><i class="fa fa-trash fa-lg"></i></button>
</div>
</li>
}
<li>
<div class="products-subtotal text-right">
Cart Subtotal <span class="subtotal-price">$ @Model.TotalPrice().ToString("00.00").Replace(",", ".")</span>
</div>
</li>
@section scripts{
<script>
$(document).ready(function() {
$(document).on("click", ".removeitem", function() {
alert($(this).text());
});
var remove = function(){
alert("trigger");
}
};
</script>
});
私は、ボタン上の複数のクリック/機能があることを知っているが、そのちょうど私がこれまで試みているものを表示するように。
この場合、 $( "。removeitem")を使用することもできます。 alert()の代わりにconsole.log()を使用することをお勧めします.F12キーを押してコンソールと開発者ツールを参照してください。 remove()関数は、定義されているコンテキストのために呼び出すことができます。グローバルコンテキストのready()から外します。 – Loenix