一组RadioButton,分别对应一个TextBox,当RadioButton被选中时,其后的TextBox置为不可用...

任务要求:一组RadioButton,分别对应一个TextBox,当RadioButton被选中时,其后的TextBox置为不可用。 //testControlPage.aspx.cs

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="testControlPage.aspx.cs" Inherits="testControlPage" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">

<title>无标题页</title>

<script language="javascript" type="text/javascript">

function RBchecked() {

var a = document.getElementsByName("a");

for (var i=0; i<a.length; i++) {

if(a.checked) {

var tb = document.getElementsByName("tb"+i);

tb[0].readOnly=true;

}

else {

var tbf = document.getElementsByName("tb"+i);

if (tbf[0].readOnly==true)

tbf[0].readOnly=false;

}

}

}

</script>

</head>

<body >

<form id="form1" runat="server" >

<div>

<asp:RadioButton id=rb0 GroupName="a" runat="server" />

<asp:TextBox id=tb0 name="tb" runat="server" />

<asp:RadioButton id=rb1 GroupName="a" runat="server" />

<asp:TextBox id=tb1 name="tb" runat="server" />

<asp:RadioButton id=rb2 GroupName="a" runat="server" />

<asp:TextBox id=tb2 name="tb" runat="server" />

<input type=button id="test" value="测试" disabled=disabled />

</div>

</form>

</body>

</html>

//testControlPage.cs

using System;

using System.Data;

using System.Configuration;

using System.Collections;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

public partial class testControlPage : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

rb0.Attributes.Add("onclick", "JavaScript:RBchecked();");

rb1.Attributes.Add("onclick", "JavaScript:RBchecked();");

rb2.Attributes.Add("onclick", "JavaScript:RBchecked();");

}

}

阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭