如何使用javascript停止按钮onclick事件?

问题描述 投票:0回答:1
javascript c# jquery
1个回答
0
投票
<div class="address-grid">
    @foreach (var item in Model.ExistingAddresses)
    {
        <div class="address-item">
                <button type="button" class="button-1 select-billing-address-button" onclick="selectBillingAddress@(item.Id)()">@T("Checkout.BillToThisAddress")</button>
                <script asp-location="Footer">
                    function selectBillingAddress@(item.Id)() {
                        if ($('#@Html.IdFor(model => model.ShipToSameAddress)')
                            .is(':checked')) {
                            setLocation(
                                '@Html.Raw(Url.RouteUrl("CheckoutSelectBillingAddress", new {addressId = item.Id, shipToSameAddress = "true"}))');
                        } else {
                            setLocation(
                                '@Url.RouteUrl("CheckoutSelectBillingAddress", new {addressId = item.Id})');
                        }
                    }
                </script>
            </div>
        </div>
    }
</div>

因为该函数是动态构建的,所以我无法描述它。我想做的就是在调用我的路线之前检查一些条件。

© www.soinside.com 2019 - 2024. All rights reserved.