1.在前天添加两个控件DropDownList和TextBox,在后台给DropDownList赋值和属性的值

View Code
            DropDownList1.Items.Add(new ListItem(" ", " "));
ListItem item
= new ListItem("1+1", "1");//绑定value
item.Attributes.Add("key", "2");//绑定属性的value
DropDownList1.Items.Add(item);
ListItem item2
= new ListItem("2+2", "2");
item2.Attributes.Add(
"key", "4");
DropDownList1.Items.Add(item2);

2.在前台

View Code
//DropDownList1后面添加onchange="ChangeDDL(this)"

<script type="text/javascript">
function ChangeDDL(obj) {
var DropDownList1
= document.getElementById("<%=DropDownList1.ClientID %>");
var TextBox1
= document.getElementById("<%=TextBox1.ClientID %>");
if (obj.value == " ") {
TextBox3.value
= "";
}
else {
var text
= obj.options[obj.selectedIndex].getAttribute("key");
TextBox1.value
= text ;
}
}
</script>

相关文章:

  • 2021-11-23
  • 2022-12-23
  • 2022-01-12
  • 2022-12-23
  • 2022-01-28
  • 2022-12-23
猜你喜欢
  • 2021-11-07
  • 2022-12-23
  • 2022-02-16
  • 2021-09-21
  • 2022-12-23
  • 2021-11-07
相关资源
相似解决方案