Javascript 使用Jquery将带有服务器端控件的行删除并添加到表中
我有一行有一个服务器端控件。根据条件的不同,我需要完全删除该行,这样屏幕阅读器就无法读取HTML,并在条件更改后重新添加 这是我正在尝试的代码,但它不起作用 我原来的ASPXJavascript 使用Jquery将带有服务器端控件的行删除并添加到表中,javascript,jquery,asp.net,Javascript,Jquery,Asp.net,我有一行有一个服务器端控件。根据条件的不同,我需要完全删除该行,这样屏幕阅读器就无法读取HTML,并在条件更改后重新添加 这是我正在尝试的代码,但它不起作用 我原来的ASPX table id="tblmain" width="100%"> <tr> <td valign="top"> <div id="studysub_animal" runat="server">
table id="tblmain" width="100%">
<tr>
<td valign="top">
<div id="studysub_animal" runat="server">
<h3>
Select the vALUE.</h3>
<asp:RadioButtonList ID="rdb_one" runat="server">
<asp:ListItem Value="Humans">Humans</asp:ListItem>
<asp:ListItem Value="Non-Human primates">Non-Human primates</asp:ListItem>
</asp:RadioButtonList>
</div>
</td>
</tr>
<tr id="tr_optional">
<td>
<h3> Select your second value</h3>
<asp:RadioButtonList ID="rdb_two" runat="server">
<asp:ListItem>Individuals</asp:ListItem>
<asp:ListItem>Population</asp:ListItem>
</asp:RadioButtonList>
</td>
</tr>
</table>
table id=“tblmain”width=“100%”>
选择值。
人类
非人灵长类
选择第二个值
个人
人口
这就是我正在写的jquery
$('#<%=rdb_one.ClientID%> input:radio').click(function () {
var currentIdone = 'Humans';
var currentId = $(this).val();
var row = $('#tr_optional');
if (currentId == currentIdone) {
if ($('#tr_studypopul').length) {
}
else {
$('#tblstudysub_animal').append(row);
}
}
else {
$('#tr_studypopul').detach();
}
});
$('#输入:收音机')。单击(函数(){
var currentIdone='人类';
var currentId=$(this.val();
变量行=$('tr#u可选');
if(currentId==currentIdone){
如果($('tr#studypopul')。长度){
}
否则{
$('tblstudysub_animal')。追加(行);
}
}
否则{
$('tr#u studypopul').detach();
}
});
任何想法。如何有条件地添加和删除行。
当页面第一次加载时,它加载的行仅根据答案隐藏或可见,就像David所说的,您不能动态添加服务器端控件。但是,既然以后会根据条件显示,为什么不隐藏它呢?尝试使用javascript document.getElementsById().style.display='none'。显示时,将“无”更改为“块”。这对我很有用。您不能用客户端代码创建服务器端控件。您可以创建与这些控件相同的HTML标记,但服务器端代码不会将它们识别为包含值的控件。相反,您必须使用类似于
Request.Form
的内容来读取这些值。