如何使用行ID检查表列中的单选按钮

时间:2021-10-22 16:52:30

I have an html table with two columns- text and pair radio button; I have set the id of the rows.I want to dynamically check a radio button using the id of the row. HTML:

我有一个带有两列的html表 - 文本和对单选按钮;我已经设置了行的id。我想使用行的id动态检查单选按钮。 HTML:

<tr class="tbrder" id="area1">
    <td class="biglable">Leadership University</td>
    <td class="smalllable">
        <div class="switch pull-right">
            <input type="radio" class="radio" value="y">Y
            <input type="radio" class="radio" value="n">N
        </div>
    </td>
</tr>

If I receive ID area1 from the backend, i want to set the radio button to Y

如果我从后端收到ID area1,我想将单选按钮设置为Y.

3 个解决方案

#1


0  

you can access to this td by use this code I don't know if there's another way better than this it's not ideal method but it works

您可以通过使用此代码访问此td我不知道是否有更好的方法,这不是理想的方法,但它的工作原理

 var myRow = document.getElementById("area1");
 var myColumn = myRow.children.item(1);
 var myRadioButtons = myColumn .getElementsByClassName("radio");
 myRadioButtons[0].checked = true; // 

then you can change it's value

然后你可以改变它的价值

#2


0  

I am assuming you have a php page as backend

我假设你有一个php页面作为后端

$.ajax({
    url:'YOUR_PHP_PAGE.php',
    ....,
    ....,
    success:function(data){
        if(data=='area1')
        {
            $(":radio[value='y']").prop("checked",true);
        }
    }
});

#3


0  

you can also use this code.

你也可以使用这段代码。

$('#area1').find(':radio[value="y"]').prop("checked",true);

#1


0  

you can access to this td by use this code I don't know if there's another way better than this it's not ideal method but it works

您可以通过使用此代码访问此td我不知道是否有更好的方法,这不是理想的方法,但它的工作原理

 var myRow = document.getElementById("area1");
 var myColumn = myRow.children.item(1);
 var myRadioButtons = myColumn .getElementsByClassName("radio");
 myRadioButtons[0].checked = true; // 

then you can change it's value

然后你可以改变它的价值

#2


0  

I am assuming you have a php page as backend

我假设你有一个php页面作为后端

$.ajax({
    url:'YOUR_PHP_PAGE.php',
    ....,
    ....,
    success:function(data){
        if(data=='area1')
        {
            $(":radio[value='y']").prop("checked",true);
        }
    }
});

#3


0  

you can also use this code.

你也可以使用这段代码。

$('#area1').find(':radio[value="y"]').prop("checked",true);