html <select>绑定 js动态添加一行。其中一个单元格是<select id="Destination'+rowNum+'" name="Destination'+rowNum+' style="width:180;"/>该页面有一个dropdown控件,当该控件的值改变时,将其相关的数据填充到select里. 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 只能用JS操作了,但是select中的数据也只能是静态的啊,刷新页面肯定就没有了啊 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %><!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 setSelect() { var dropdown = document.getElementById("<%=DropDownList1.ClientID %>"); var s = document.getElementById("Select1"); if (dropdown.value == "Microsoft") { s.options.length = 0; s.options.add(new Option("Dotnet", "Dotnet")); s.options.add(new Option("C#", "C#")); s.options.add(new Option("Win7", "Win7")); } if (dropdown.value == "IBM") { s.options.length = 0; s.options.add(new Option("Eclipse", "Eclipse")); s.options.add(new Option("DB2", "DB2")); } } </script></head><body> <form id="form1" runat="server"> <asp:DropDownList ID="DropDownList1" runat="server" onchange="return setSelect();"> <asp:ListItem></asp:ListItem> <asp:ListItem>Microsoft</asp:ListItem> <asp:ListItem>IBM</asp:ListItem> </asp:DropDownList> </form> <select id="Select1" name="D1"> <option></option> </select></body></html> <script language="javascript" type="text/javascript"> var rowNum = '<%=ViewState["rowNum"] %>'; if (rowNum == 0) rowNum = 1; function CreatTicketPrice() { var ticketPriceID = newGuid(); arrCols = new Array( '<select id="Destination'+rowNum+'" name="Destination'+rowNum+' style="width:180;"/>', '<select id="IsEndStation' + rowNum + '" name="IsEndStation' + rowNum + '"><option>是</option><option> 否</option></select>', '<input type="text" name="TravelTime' + rowNum + '" class="infoInput" />'); InsertRow(arrCols); rowNum++; document.getElementById("hdCount").value = rowNum;} function newGuid() { var guid = ""; for (var i = 1; i <= 32; i++) { var n = Math.floor(Math.random() * 16.0).toString(16); guid += n; if ((i == 8) || (i == 12) || (i == 16) || (i == 20)) guid += "-"; } return guid; } function InsertRow(cols) { arrCols = new Array(); arrCols = cols; row1 = tbTicketPriceList.insertRow(); for (i = 0; i < arrCols.length; i++) { cell1 = row1.insertCell(); cell1.style.cssText = " text-align: left; padding: 2px; background-color: #FFFFFF; height: 30px;"; cell1.innerHTML = arrCols[i]; } } </scirpt><html><body><form runat ="server"> <input type="hidden" name="hdCount" id="hdCount" runat="server" /> <input id="btnAdd" type="button" value="新增票价" onclick="CreatTicketPrice();" /> <asp:DropDownList ID="ddlLineType" runat="server" AutoPostBack="True"> <asp:ListItem>广洲</asp:ListItem> <asp:ListItem>东莞</asp:ListItem> </asp:DropDownList></form></body></html>当选择东莞时,把东莞的城区加载到Destination里。当新一行,如果dropdownlist默认值是广洲,则把广洲的城区加载到Destination里. 看下js的数据绑定,dropdown改变的时候select重新绑定下 AutoPostBack="True"自动回发了,js生成的代码会没有的,你采用ajax去读取数据就可以了 这种查询,怎么做,是什么技术? update 字段值叠加更新问题 MySQL Connector/NET连接mysql数据库乱码 IIS遇到的关于.net的困惑 怎样获取页面的所有控件id 谁能帮帮我 【求解决方案】怎样利用c#使一个文件,从一台机器复制到另一台机器,不用Webform的file控件 请问用c#能够读出网卡的mac地址么? 关于webparts中控件的应用 关于SQL查询查找时间类型字段的问题,请高手指点 ASP.NET中怎么把动态页面转换为静态页面? 请教各位高手,有关文件下载操作的问题!
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %><!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 setSelect() {
var dropdown = document.getElementById("<%=DropDownList1.ClientID %>");
var s = document.getElementById("Select1");
if (dropdown.value == "Microsoft") {
s.options.length = 0;
s.options.add(new Option("Dotnet", "Dotnet"));
s.options.add(new Option("C#", "C#"));
s.options.add(new Option("Win7", "Win7"));
}
if (dropdown.value == "IBM") {
s.options.length = 0;
s.options.add(new Option("Eclipse", "Eclipse"));
s.options.add(new Option("DB2", "DB2"));
}
}
</script></head>
<body>
<form id="form1" runat="server">
<asp:DropDownList ID="DropDownList1" runat="server" onchange="return setSelect();">
<asp:ListItem></asp:ListItem>
<asp:ListItem>Microsoft</asp:ListItem>
<asp:ListItem>IBM</asp:ListItem>
</asp:DropDownList>
</form>
<select id="Select1" name="D1">
<option></option>
</select>
</body>
</html>
var rowNum = '<%=ViewState["rowNum"] %>';
if (rowNum == 0)
rowNum = 1;
function CreatTicketPrice() {
var ticketPriceID = newGuid();
arrCols = new Array(
'<select id="Destination'+rowNum+'" name="Destination'+rowNum+' style="width:180;"/>',
'<select id="IsEndStation' + rowNum + '" name="IsEndStation' + rowNum + '"><option>是</option><option> 否</option></select>',
'<input type="text" name="TravelTime' + rowNum + '" class="infoInput" />');
InsertRow(arrCols);
rowNum++;
document.getElementById("hdCount").value = rowNum;
}
function newGuid() {
var guid = "";
for (var i = 1; i <= 32; i++) {
var n = Math.floor(Math.random() * 16.0).toString(16);
guid += n;
if ((i == 8) || (i == 12) || (i == 16) || (i == 20))
guid += "-";
}
return guid;
}
function InsertRow(cols) {
arrCols = new Array();
arrCols = cols;
row1 = tbTicketPriceList.insertRow();
for (i = 0; i < arrCols.length; i++) {
cell1 = row1.insertCell();
cell1.style.cssText = " text-align: left; padding: 2px; background-color: #FFFFFF; height: 30px;";
cell1.innerHTML = arrCols[i];
}
}
</scirpt>
<html>
<body>
<form runat ="server">
<input type="hidden" name="hdCount" id="hdCount" runat="server" />
<input id="btnAdd" type="button" value="新增票价" onclick="CreatTicketPrice();" />
<asp:DropDownList ID="ddlLineType" runat="server" AutoPostBack="True">
<asp:ListItem>广洲</asp:ListItem>
<asp:ListItem>东莞</asp:ListItem>
</asp:DropDownList>
</form>
</body>
</html>
当选择东莞时,把东莞的城区加载到Destination里。
当新一行,如果dropdownlist默认值是广洲,则把广洲的城区加载到Destination里.