Gridview 中的radio唯一选中

こ雲淡風輕ζ 提交于 2020-02-16 07:38:22

 

 

方法1:如果你只是想唯一选中,不触发任何事件:你可以用前台控件<input id = "select" type = "radio" />

方法2:Gridview中的radio用服务器控件

 

后台:this._offerCounties.Attributes.Add("onclick", "postBackByObject()");

前台代码:

<script language="javascript">
        function postBackByObject()
        {
            var element = window.event.srcElement;
            if (element.tagName == "INPUT" && element.type == "checkbox")
            {
                var checkedState = element.checked;
                while (element.tagName != "TABLE")
                element = element.parentElement;

                UnCheck(element);
                element = element.nextSibling;
                if (element == null)
                return;

                var childTables = element.getElementsByTagName("TABLE");
                for (var tableIndex = 0; tableIndex < childTables.length; tableIndex++)
                Check(childTables[tableIndex], checkedState);
            }
        }

        function UnCheck(table)
        {
            if (table == null || table.rows[0].cells.length == 2) // This is the root
                return;
            var parentTable = table.parentElement.previousSibling; 
            Check(parentTable, false);
            UnCheck(parentTable);
        }

        function Check(table, checked)
        {
            var checkboxIndex = table.rows[0].cells.length - 1;    
            var cell = table.rows[0].cells[checkboxIndex];
            var checkboxes = cell.getElementsByTagName("INPUT");
            if (checkboxes.length == 1)
                checkboxes[0].checked = checked;
        }
</script>

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!