关于select的onchange事件的问题
<table >
<tr>
<td valign="middle"><div align="center"><img alt="" id="face" src="" runat="server" /></div></td>
</tr>
</table>
<p align="center"> <select id="lstPic" name="lstPic" runat="server" onchange="document.images['face'].Src=options[selectedIndex].value;" >
</select>
选择头像</p>
下面是后台代码:
public void InitlstPic()
{
string currentDir, fileName, imgDir;
FileInfo fi;
currentDir = Server.MapPath(".") + "\\pic\\gg";
imgDir = "pic\\gg";
女.Checked = false;
DirectoryInfo dir = new DirectoryInfo(currentDir);
foreach (FileSystemInfo fsi in dir.GetFileSystemInfos())
{
if (fsi is FileInfo)
{
fi = (FileInfo)fsi;
fileName = fi.Name;
if ((fi.Extension == ".gif") || (fi.Extension == ".jpg"))
lstPic.Items.Add(new ListItem(fileName, imgDir + "\\" + fileName));
}
}
lstPic.SelectedIndex = 0;
face.Src = lstPic.Value;
}
为什么select的onchange事件触发不了啊。每次执行的时候都只能显示lstPic.SelectedIndex 所给定的值所对应的那张图片。
可是换做“alert('');”是可以触发的,
onchange="document.images['face'].Src=options[selectedIndex].value;"
这句哪里错了啊?还是后台的代码有问题。 --------------------编程问答-------------------- ·双线主机 100M/35元/年,免费送数据库(自选MY/MSSQL)
·详情请访问:http://www.515dns.com --------------------编程问答-------------------- Protected void Page_Load(object sender,EventArgs e)
{
lstPic.Attributes.Add("onchange","javascript:ChoosePic()");
}
<script>
function ChoosePic()
{
document.images['face'].Src=document.all.lstPic.value;
}
</script>
试试 --------------------编程问答-------------------- 还是不行啊。document.images['face'].加点后弹出的选择表中都没有Src啊
补充:.NET技术 , ASP.NET