2024年5月30日发(作者:)

通过JavaScript对DropDownList的操作 / 初学

文章来源:网络转载 点击数:962 更新时间:2009-9-19 10:32:53 字体:[大 中 小]

收藏到:

1.在客户端编写 “OnSelectedIndexChanged” 事件

由于在客户端不识别 OnSelectedIndexChanged 事件,但是我们可以写其 onchange 事件,然后为

DropDownList 动态添加属性(onchange)。

>

("onchange", "return SelectionChanged();");

2.在客户端动态绑定 DropDownList 的值

var option = Element("option");

= message[1];

= message[0];

(option);

3.通过 javascript 获取 DropDownList 的值

var dropDownList = mentById("SelectProvince");

var provinceId = s[edIndex].value;

3.通过 Ajax 实现省市联动。

我做了一个 Test ,不多说,看代码:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="" Inherits="_Default" %>

">

Home Page

ged">





using System;

using uration;

using ;

using ;

using ;

using ty;

using ;

using ntrols;

using trols;

using ts;

using ;

using ent;

public partial class _Default :

{

string connectionString = tionStrings["DbConn"].ConnectionString;

protected void Page_Load(object sender, EventArgs e)

{

if (!Back)

{

ProvinceBind();

("onchange", "return SelectionChanged();");

}

}

private void ProvinceBind()

{

using (SqlConnection conn = new SqlConnection(connectionString))

{

();

using (SqlCommand cmd = Command())

{