Jquery基于单选按钮的功能是选择

本文关键字:功能 选择 单选按钮 Jquery | 更新日期: 2023-09-27 18:13:56

我想在另一个函数成功运行后,基于当前的单选按钮选择调用特定单选按钮的data-url。

这是我的单选按钮组:

<form action="/ALS/RejectRecordAnalysis/1" method="post">
    <span id="wrapper_cra" class="form-group">
        <span><label for="">TEST1</label></span>
        <span id="button-spacing">
            <input class="" data-url="/ALS/RejectRecordAnalysisCRA?business=1&amp;_cra_id=1" id="radiobutton1" name="_cra.agency_name" type="radio" value="{ id = 1 }" />  
        </span>   
        <span><label for="">TEST2</label></span>
        <span id="button-spacing"> 
            <input class="" data-url="/ALS/RejectRecordAnalysisCRA?business=1&amp;_cra_id=2" id="radiobutton2" name="_cra.agency_name" type="radio" value="{ id = 2 }" />  
        </span>   
        <span><label for="">TEST3</label></span>
        <span id="button-spacing"> 
            <input class="" data-url="/ALS/RejectRecordAnalysisCRA?business=1&amp;_cra_id=3" id="radiobutton3" name="_cra.agency_name" type="radio" value="{ id = 3 }" />  
        </span>   
        <span><label for="">TEST4</label></span>
        <span id="button-spacing"> 
            <input class="" data-url="/ALS/RejectRecordAnalysisCRA?business=1&amp;_cra_id=4" id="radiobutton4" name="_cra.agency_name" type="radio" value="{ id = 4 }" />  
        </span>   
    </span>
</form>

希望从这个成功块运行:编辑我在成功块中添加了一点javascript。但是,.val()函数只返回所选单选按钮的id,并且在尝试$时抛出错误。ajax

success: function (result) {
    if (result.success) {
        $('#myModal').modal('hide');
        var checked = $("#wrapper_cra input[type='radio']:checked").val();
                $.ajax({
                    url: $(checked).data('url'),
                    type: 'GET',
                    data: checked,
                    success: function (result) {
                        $("#scroll-grid").html(result);
                    }
                });
    } else {
         $('#myModalContent').html(result);
         bindForm();
    }
}

Jquery基于单选按钮的功能是选择

我已经解决了上述问题。在成功块中,我添加了以下代码:

var checked = $("#wrapper_cra input[type='radio']:checked").attr('data-url');
                $.ajax({
                    url: checked,
                    type: 'GET',
                    success: function (result) {
                        $("#scroll-grid").html(result);
                    }

选中的变量包含适当的单选按钮的data-url,然后$.ajax函数运行该url,我返回一个html部分视图,其中包含更新的信息。