单选按钮更改事件在jquery&& MVC

时间:2017-05-03 18:08:15

标签: javascript jquery asp.net-mvc

我有两个确定付款方式的单选按钮。 我想什么时候"银行"点击单选按钮显示相关链接,点击"充电" ,show account of account.i写了这段代码: XAML:

  

@ Html.RadioButton(" PaymentType"," bank",true)来自银行港口的付款      @ Html.ActionLink("连接和支付"," PaymentFactor"," PaymentFactor")
          @ Html.RadioButton(" PaymentType"," charge",false)来自帐户费用的付款      @ Html.Display(" txtcharge","您的帐户费用:" + TempData ["费用"],null,新{id =" txtcharge& #34;})

JS:

<script type="text/javascript">
$(document).ready(function () {
    $("#txtcharge").hide();
    $("input:radio[name=PaymentType]").change(function () {
        window.alert($(this).val());
        if ($(this).val() == "bank") {
            $("#txtbank").show();
        }
        else {
            $("#txtbank").hide();
        }
        if (this.value == "charge") {
            $("#txtcharge").show();
        }
        else {
            $("#txtcharge").hide();
        }
    });
});

change事件无效。

更新:我的HTML

    @{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@using StoreProject.Areas.User
<h2>Index</h2>
@if (!User.Identity.IsAuthenticated)
{
    Response.Redirect("~/Security/Login");
}
@if (TempData["Msg"] != null)
{
    <div class="alert alert-dismissable alert-info">
        <button type="button" class="close" data-dismiss="alert">×</button>
        @TempData["Msg"].ToString()
    </div>
}
@if(Session["cart"] == null)
{
    Response.Redirect("~/Common/Home");
}
else
{
    long SumPrice = 0;
    if ((List<CartViewModel>)Session["cart"] != null)
    {
        foreach (CartViewModel item in (List<CartViewModel>)Session["cart"])
        {
            SumPrice += item.TotalPrice;
        }
            <div>
                total : @SumPrice 
            </div>
     @Html.RadioButton("PaymentType", "bank", true)<div>payment from bank port</div>
   <div id="txtbank">@Html.ActionLink("connect and payment", "PaymentFactor", "PaymentFactor")</div>    
        @Html.RadioButton("PaymentType", "charge", false)<div>payment from account charge </div>
   <div id="txtcharge">@Html.Display("txtcharge", " you account charge: " + TempData["charge"], null, new { id = "txtcharge" })</div>    
    }
}
<script type="text/javascript">
    $(document).ready(function () {
        $("#txtcharge").hide();
        $("input[type=radio][name='PaymentType']").change(function () {
            window.alert($(this).val());
            if ($(this).val() == "bank") {
                $("#txtbank").show();
            }
            else {
                $("#txtbank").hide();
            }
            if (this.value == "charge") {
                $("#txtcharge").show();
            }
            else {
                $("#txtcharge").hide();
            }
        });
    });
</script>

1 个答案:

答案 0 :(得分:1)

更改选择器
$("input:radio[name=PaymentType]")

$("input[type=radio][name=PaymentType]")