Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/374.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
asp.net中的javascript 对 不_Asp.net_Javascript - Fatal编程技术网

asp.net中的javascript 对 不

asp.net中的javascript 对 不,asp.net,javascript,Asp.net,Javascript,我想通过单击RadioButtonList启用文本框,而不使用autopostback=true。如何使用JavaScript实现这一点?您可以使用jQuery操作输入的启用状态(文本框的HTML转换),或者使用ASP.NET Ajax,以便在更新面板中设置这两个控件。在这种情况下,您不会看到在回发时重新加载页面,为了在其他事件中更改文本框的状态,必须重新加载页面。 Tbh我会选择ASP.NET Ajax,因为我的经验表明,当涉及到复杂的内容时,jQuery与ASP.NET控件不能很好地配合使用

我想通过单击
RadioButtonList
启用
文本框
,而不使用
autopostback=true
。如何使用JavaScript实现这一点?

您可以使用jQuery操作输入的启用状态(文本框的HTML转换),或者使用ASP.NET Ajax,以便在更新面板中设置这两个控件。在这种情况下,您不会看到在回发时重新加载页面,为了在其他事件中更改文本框的状态,必须重新加载页面。 Tbh我会选择ASP.NET Ajax,因为我的经验表明,当涉及到复杂的内容时,jQuery与ASP.NET控件不能很好地配合使用,即ASP.NET使用javascript进行事件激活,这可能会导致jQuery或ASP.NET无法按您的预期工作


祝您在更新面板方面好运…

每个列表项都会呈现一个具有相同名称参数的单选按钮;我建议运行该应用程序并查看生成的源代码,了解您需要做些什么来收听单选按钮事件。单选按钮列表的ID本质上是name参数,因此可以将单选按钮组作为(使用JQuery):

$(“输入[名称=”))。单击(函数(){
var tb=$(“#textboxid”);
//在这里做点什么;这指向单选按钮
});
嗯。

给你:

$("input[name='<%= rbl.ClientID%>']").click(function() {
   var tb = $("#textboxid");
   //do something here; this points to the radio button
});

受保护的void RdoBtnHasNotified_PreRender(对象发送方,事件参数e)
{
foreach(RdoBtnHasNotified.Items中的ListItem项)
Add(“onclick”,string.Format(“toggleTextBox(this,{0}”);”,TxtHowNotified.ClientID));
}
功能切换文本框(单选按钮,文本框ID){
document.getElementById(textBoxId).disabled=radioButton.value!=“1”;
}
对
不

按以下方式编写代码

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
    protected void RdoBtnHasNotified_PreRender(object sender, EventArgs e)
    {
        foreach (ListItem item in RdoBtnHasNotified.Items)
            item.Attributes.Add("onclick", string.Format("toggleTextBox(this,'{0}');", TxtHowNotified.ClientID));
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>

    <script type="text/javascript">
        function toggleTextBox(radioButton, textBoxId) {
            document.getElementById(textBoxId).disabled = radioButton.value != "1";
        }
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:RadioButtonList ID="RdoBtnHasNotified" OnPreRender="RdoBtnHasNotified_PreRender"
            runat="server" RepeatDirection="Horizontal">
            <asp:ListItem Value="1">Yes</asp:ListItem>
            <asp:ListItem Value="0" Selected="True">No</asp:ListItem>
        </asp:RadioButtonList>
        <asp:TextBox ID="TxtHowNotified" runat="server" TextMode="MultiLine" MaxLength="100" Enabled="false"></asp:TextBox>
    </div>
    </form>
</body>
</html>

$(文档).ready(函数(){
$(“输入[name='RdoBtnHasNotified']”)。更改(函数(){
$(“输入[name='RdoBtnHasNotified']:选中”).val()='1'?$('TxtHowNotified').removeAttr(“禁用”):$('TxtHowNotified').attr('disabled','true');
});
});

并且还禁用文本框(Enabled=“false”),因为“RdoBtnHasNotified”的初始值为“No”。

使用jQuery,您可以通过挂接单选按钮上的更改来获得相当自定义的结果

<script type="text/javascript">
    $(document).ready(function() {
        $("input[name='RdoBtnHasNotified']").change(function() {
        $("input[name='RdoBtnHasNotified']:checked").val() == '1' ? $('#TxtHowNotified').removeAttr("disabled")  : $('#TxtHowNotified').attr('disabled', 'true'); 

        });
    });

</script>

$(“#>输入[type=radio]”)。更改(函数(){
//只要单选按钮列表的控件之一发生更改,就会调用此函数
//$(this)变量引用触发事件的输入控件
var txt=$(“#”);
如果($(this.val()=“1”){
txt.removeAttr(“禁用”);
}否则{
txt.attr(“禁用”,真);
}
});
$('#>input[type=radio]')。单击(函数()
{
var txtbox=$(“#”);
if($(this).val()=='1')
{
document.getElementById('#')。disabled=false;
}
其他的
{
document.getElementById('#')。disabled=true;
}
});
我认为在IE中使用change事件不会触发

<script type="text/javascript">
    $(document).ready(function() {
        $("input[name='RdoBtnHasNotified']").change(function() {
        $("input[name='RdoBtnHasNotified']:checked").val() == '1' ? $('#TxtHowNotified').removeAttr("disabled")  : $('#TxtHowNotified').attr('disabled', 'true'); 

        });
    });

</script>

$("#<%= RdoBtnHasNotified.ClientID %> > input[type=radio]").change(function(){
  // this function is called whenever one of the radio button list's control's change
  // the $(this) variable refers to the input control that triggered the event
  var txt = $("#<%= TxtHowNotified.ClientID %>");
  if($(this).val()=="1") {
    txt.removeAttr("disabled");
  } else {
    txt.attr("disabled", true);
  }
});
$('#<%= RdoBtnHasNotified.ClientID %> > input[type=radio]').click(function()
{
  var txtbox = $('#<%= TxtHowNotified.ClientID %>');
  if($(this).val() == '1')
  {
     document.getElementById('#<%= TxtHowNotified.ClientID %>').disabled = false;
  }
  else
  {
     document.getElementById('#<%= TxtHowNotified.ClientID %>').disabled = true;
  }
});