js处理的listBox列表后台取值(带js函数)

<!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 src="../jquery/jquery-1.2.6.min.js" type="text/javascript"></script>
<script type="text/javascript">

function addBusiness() {

var first = document.getElementById("ddl");
var second = document.getElementById("ddl2");
var third = document.getElementById("ddl3");
var fourth = document.getElementById("fourth");
if (fourth.options.length >= 6) {
alert("主营行业最多可以添加 6 个,不能再添加!");
return;
}
if (first.value == "" ||
second.options.length > 0 && second.value == "" ||
third.options.length > 0 && third.value == "") {
alert("请选择行业类别再点 [添加] 按钮!");
return;
}
var value, text;
if (third.value != "") {
value = third.value;
text = first.options[first.selectedIndex].innerHTML + " >> " +
second.options[second.selectedIndex].innerHTML + " >> " +
third.options[third.selectedIndex].innerHTML;
} else if (second.value != "") {
value = second.value;
text = first.options[first.selectedIndex].innerHTML + " >> " +
second.options[second.selectedIndex].innerHTML;
} else {
value = second.value;
text = first.options[first.selectedIndex].innerHTML;
}
for (var i = 0; i < fourth.options.length; i++)
if (fourth.options[i].value == value) // 发现重复,则不再添加
return;
fourth.appendChild(createOption(text, value));
}

function delBusiness() {
var fourth = document.getElementById("fourth");
if (fourth.value == "") {
alert("请选择要删除的行业类别再点 [删除] 按钮!");
return;
}
fourth.removeChild(fourth.options[fourth.selectedIndex]);
}
function createOption(name, value) {
var option = document.createElement("option");
option.setAttribute("value", value);
option.appendChild(document.createTextNode(name));
return option;
}

$(document).ready(function () {
$("#Button1").click(function () {
doFourth();

})
});

function doFourth() {
var fourth = document.getElementById("fourth");

if (fourth.options[0] == null) {
alert("请添加主营行业!");
return false;
}
var mBusiness = fourth.options[0].value;

for (var i = 1; i < fourth.options.length; i++)
mBusiness = mBusiness + "," + fourth.options[i].value;
document.getElementById("mBusiness").value = mBusiness;

return true;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager><div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:ListBox ID="ddl" Height="160px" runat="server" AppendDataBoundItems="True"
DataTextField="ic_name" DataValueField="ic_selfid"
OnSelectedIndexChanged="changeFirst" AutoPostBack="true">
<asp:ListItem Value="">--请选择--</asp:ListItem>
</asp:ListBox>
<asp:ListBox ID="ddl2" runat="server" Height=160px AppendDataBoundItems="True" DataTextField="ic_name" DataValueField="ic_selfid"
OnSelectedIndexChanged="changeSecond" AutoPostBack="true">
<asp:ListItem Value="">--请选择--</asp:ListItem>
</asp:ListBox>
<asp:ListBox ID="ddl3" runat="server" Height=160px DataTextField="ic_name" DataValueField="ic_selfid" >
<asp:ListItem Value="">--请选择--</asp:ListItem></asp:ListBox>

</ContentTemplate>
</asp:UpdatePanel> <BR> </BR>
<input id="btnAdd" type="button" value="添加↓"
onclick="addBusiness()"/>
<input id="btnDel" type="button" value="删除×"
onclick="delBusiness()"/> <BR></BR>
<asp:ListBox ID="fourth" runat="server" Width="340px"></asp:ListBox>
<br />
<select name="fourth" size="8" id="Select1" style="width:340px;" onmouseover="checkMainBuniss()">

</select>
<%--<input type="hidden" name="company.mainBusiness" value="" id="mBusiness"/>--%>
<asp:HiddenField ID="mBusiness" runat="server" />
<asp:Button ID="Button1" runat="server" onclick="Button1_Click1"
Text="Button" />
<br />
</div>
</form>

</body>

</html>

posted on 2011-12-02 16:28  xupeng  阅读(649)  评论(0编辑  收藏  举报

导航