为RadioButtonList添加页面的onclick事件

来源:互联网 发布:搜狗关键词优化软件 编辑:程序博客网 时间:2024/05/07 22:43

在head 中写脚本如下:

    <script language="javascript" type="text/javascript">
       function drpchange(rad)
       {      
          
            var drp = document.getElementById("dv1");
            var text = document.getElementById('txtquery');            
            if(rad.value=="5")
            {              
               text.onclick = function()
               {                   
                    parent.open('selectdate.aspx','','height=250,width=250');
                    text.ReadOnly = true;
               };              
            }
            else
            {
              text.ReadOnly = false;
              text.onclick = function(){};
              text.value = '';
            }
            if(rad.value=="1")
            {
                drp.style.display="block";
                text.style.display="none";
            }
            else
            {
                drp.style.display="none";
                text.style.display="";
            }
       }
    </script>

此脚本为下面要为RadioButtonList添加的onclick事件.

在Page_Load()里里面写入如下代码:

for (int i = 0; i < RadioButtonList1.Items.Count; i++)
        {          
            RadioButtonList1.Items[i].Attributes.Add("onclick", "drpchange(this)");
        }

一定要注意不要将上面的写在if(!Page.IsPostBack)里面!

 

原创粉丝点击