如何用JavaScrip取ListBox中选中内容,并将取得值相连接后赋给页面的TextBox控件,C#可以这样,但会刷新页面:private void lstBoxNodeName_SelectedIndexChanged(object sender, System.EventArgs e)
{
string tempStr = string.Empty;
string tempValue = string.Empty;
foreach(ListItem item in this.lstBoxNodeName.Items)
{
if(item.Selected)
{
tempStr += item.Text + "|";
tempValue += item.Value + "|";
}
}
tempStr = tempStr.Trim('|');
tempValue = tempValue.Trim('|');
this.txtNodeName.Text = tempStr;
this.DRow["InspectionTourNodeID"] = tempValue;
this.DRow["InspectionTourNodeName"] = tempStr;
}
如何用JavaScrip同样的功能??
{
string tempStr = string.Empty;
string tempValue = string.Empty;
foreach(ListItem item in this.lstBoxNodeName.Items)
{
if(item.Selected)
{
tempStr += item.Text + "|";
tempValue += item.Value + "|";
}
}
tempStr = tempStr.Trim('|');
tempValue = tempValue.Trim('|');
this.txtNodeName.Text = tempStr;
this.DRow["InspectionTourNodeID"] = tempValue;
this.DRow["InspectionTourNodeName"] = tempStr;
}
如何用JavaScrip同样的功能??
解决方案 »
- 以钟表样式显示世界不同时间(列出4,5个国家的就好)
- 多级类别 点击刷新同时展开有没有人做过啊
- 不知为什么,我的VS2008每次保存或者后退时,要停顿好久,有点假死的感觉!
- 关于多表的联合查询有没有比较简单的方法...
- 用 ajax 的 AsyncPostBackErrorMessage捕捉异常,遇到的问题.........
- 验证控件发布后失效
- 救命啊,clone()上的问题
- 关于OA,大家请帮忙.
- 简单的问题
- 关于vs自带验证控件的问题
- 怎样在 ASP.NET2.0中的aspx页面里播放 flash 文件啊?请高手指教
- 上传文件保存成功后,立即用FTP类来上传到服务器时提示文件正在由另一进程使用
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<SCRIPT LANGUAGE="JavaScript">
<!--
function getValue(value) {
alert(value);
}
//-->
</SCRIPT>
</HEAD><BODY>
<SELECT NAME="listBox1" onChange="getValue(this.value)">
<option value="1">1<option>
<option value="2">2<option>
<option value="3">3<option>
</SELECT>
</BODY>
</HTML>
<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript">
function onSelChangle() {
var e = event.srcElement;
var tb = document.getElementById('TextBox1');
tb.value = e.options[e.selectedIndex].value;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ListBox ID="ListBox1" runat="server" Width="237px"></asp:ListBox>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></div>
</form>
</body>
</html>public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
for(int i = 0; i < 10; i++)
{
ListBox1.Items.Add("Item " + i);
}
ListBox1.Attributes.Add("onchange", "onSelChangle()");
}
}
tb.value = document.all.item("ListBox1").options[document.all.item("ListBox1").selectedIndex].value;
</script>