这个好像没有什么难的吧,假设第一题是checkbox1,第一题的选项是checkboxlist1,第二题是checkbox2等等,依次类推,当点击checkbox1时,checkboxlist1为可用enable,选择checkbox2时,checkboxlist2为enable,
等等,依次类推,用swith..case语句就搞定了,应该没什么的,难度在于你的判断可能出现嵌套,逻辑有点复杂而已
等等,依次类推,用swith..case语句就搞定了,应该没什么的,难度在于你的判断可能出现嵌套,逻辑有点复杂而已
如果是一个一个的判断,这也没有难度,但是我是n个类似上面的题目。。
超过150个,不可能写150多条判断吧,请各位发表以下
for(int i=1;i<=150;i++)
{
Response.Write("if(document.all.checkbox" + i + ".checked)");
Response.Write("{");
Response.Write("……");
Response.Write("}");
}
因为我使用是HtmlInputText Control,但是我在js里访问它。
如果是TextBox
可以用 FormName.TextBoxName.Text可以得到它的值。
但是使用HtmlInputText Control
我用FormName.HtmlInputTextName.Text
or FormName.HtmlInputTextName.Value都不行
主要是我不想使用checkboxlist 的_CheckedChanged来刷新页面
checkboxlist control
而并非是checkbox... :-)
希望大家能解决本问题。其实归根到底,其实是js的问题。而非真正的.Net技术。
原来的设计是点中1的选择,下面的A B C 选择的enable为true,
如果点中了A的选择,A后面的输入框TextBox,or HtmlInputText的Enable为true,而此输入框还必须符合我的定义格式
[ ] 1.中国在那里
[]A 亚洲(后面带输入框)
[]B 东南部(后面带输入框)
[]C 世界(后面带输入框)
WebForm1.Text1.disabled=true;
这样根本不起作用。你测试一下就知道
<head>
<script language="C#" runat="server">
void Page_Load() {
string[] strArr={"中国在那里,亚洲,东南部,世界",
"设计程序,Basic,VC,C#,ASP.NET",
"那个网站比较好,Microsoft,Ibm,Sun,HP,New"}; for(int i=0;i<strArr.Length;i++){
CheckBox cb=new CheckBox();
string[] tmpArr=strArr[i].Split(',');
cb.ID="cb"+i;
cb.Text=tmpArr[0];
frm.Controls.Add(cb);
CheckBoxList cbl=new CheckBoxList();
cbl.ID="cbl"+i;
cbl.Style["margin-left"]="10px";
for(int j=1;j<tmpArr.Length;j++)
cbl.Items.Add(new ListItem((char)(64+j)+"."+tmpArr[j]));
frm.Controls.Add(cbl);
}
Button b=new Button();
b.Text="提交";
b.Attributes["onclick"]="return check();";
frm.Controls.Add(b);
}
</script>
<form runat=server id=frm></form>
<script>
function check(){
var o=document.getElementsByTagName("input"),sel="";
for(var i=0;i<o.length;i++){
if(o[i].type!="checkbox")continue;
if(o[i].checked&&/^cb\d+$/.test(o[i].name)){
if(sel!=""){alert(sel+"选中了就要回答");return false;}
sel="cbl"+o[i].name.substr(2)+":";continue;
}
if(sel!=""&&o[i].checked&&o[i].name.substring(0,sel.length)==sel)sel="";
}
if(sel!=""){alert(sel+"选中了就要回答");return false;}
}
</script>
先回答我第一个小问题
如何用 js控制TextBox的enable属性
代码如下
.aspx
function aa()
{
alert("ok");
WebForm2.TextBox2.enable=false;
WebForm2.TextBox2.bgcolor="#ff0000";
}
</script>
<form id="WebForm2" method="post" runat="server">
<asp:Button id="Button1" style="Z-INDEX: 105; LEFT: 267px; POSITION: absolute; TOP: 332px" runat="server" Text="Button"></asp:Button>
<asp:TextBox id="TextBox2" style="Z-INDEX: 106; LEFT: 74px; POSITION: absolute; TOP: 304px" runat="server"></asp:TextBox>
</form>
实现的效果是点击button,Textbox颜色和enable都改变。
void Page_Load(){
Button1.Attributes["onclick"]="javascript:aa();";
}
</script>
<script>
function aa()
{
alert("ok");
WebForm2.TextBox2.disabled=true;
WebForm2.TextBox2.style.backgroundColor="#ff0000";
window.event.returnValue=false;
}
</script>
<form id="WebForm2" method="post" runat="server">
<asp:Button id="Button1" style="Z-INDEX: 105; LEFT: 267px; POSITION: absolute; TOP: 332px" runat="server" Text="Button"></asp:Button>
<asp:TextBox id="TextBox2" style="Z-INDEX: 106; LEFT: 74px; POSITION: absolute; TOP: 304px" runat="server"></asp:TextBox>
</form>
你好,问题解决一半,.backgroundColor颜色没有问题。
但是 disabled不起作用,请帮忙正式测试一下。问题看起来简单。内置复杂。
但是我的textbox可以写的进内容。你说呢
先blur再focus就可以了
或者.readOnly=true
<HTML>
<HEAD>
</HEAD>
<body>
<form id="WebForm2" method="post" runat="server">
<asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
<INPUT type="button" value="Button" onclick="aa()">
</form>
<script language=javascript>
function aa()
{
WebForm2.TextBox1.disabled=true;
WebForm2.TextBox1.style.backgroundColor="#E0E0E0";
}
</script>
</body>
</HTML>
你跟qiushuiwuhen(秋水无恨) ( ) 信誉:115 2002-11-28 18:19:13 得分:0 发的有区别吗?
To: 秋水无恨
IE的bug,可能,那么应该怎么加blur呢,给我例子,真奇怪我是使用ie6.0sp1
使用readOnly=true解决问题一
问题二:
怎么点击checkbox激发js事件而使用textbox.readOnly=true;
求js代码。非codebehide方式。。
WebForm2.aspx<HTML>
<HEAD>
</HEAD>
<body>
<form id="WebForm2" method="post" runat="server">
<INPUT type="checkbox" name="c1" onclick="aa()">
<asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
</form>
<script language="javascript">
function aa()
{
if(WebForm2.c1.checked)
{
WebForm2.TextBox1.disabled=true;
WebForm2.TextBox1.style.backgroundColor="#E0E0E0";
}
else
{
WebForm2.TextBox1.disabled=false;
WebForm2.TextBox1.style.backgroundColor="#FFFFFF";
}
}
</script>
</body>
</HTML>
怎么点击checkbox激发js事件而使用textbox.readOnly=true;
求js代码。非codebehide方式。。
代码如下
document.all.WebTest.CheckBox2.disabled=true; document.all.WebTest.CheckBox2.style.backgroundColor="#ff0000";
document.all.WebTest.TextBox1.readOnly=true; document.all.WebTest.TextBox1.style.backgroundColor="#ff0000";
问题三:
如果要一个checklstbox(假设有三个checkbox,名字分别是id=CheckBoxList1_0,CheckBoxList1_1,CheckBoxList1_2) 该怎么对应控制每个textbox1_0 ,textbox1_1,textbox1_2
请使用循环语句