【发布时间】:2021-09-27 13:54:15
【问题描述】:
我使用 'label1' 像全局变量一样将信息从 1 个脚本 (type="text/javascript") 传递到另一个脚本 (runat="server"),但是 setAttribute("src",.. .) 使用变量似乎不起作用。请注意,如果硬编码,它确实有效。这是我的 ASP.Net 代码的一部分:
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<script type="text/javascript" >
var soundObject = null;
function PlaySound() {
if (soundObject != null) {
document.body.removeChild(soundObject);
soundObject.removed = true;
soundObject = null;
}
soundObject = document.createElement("embed");
soundObject.setAttribute("src", label1.Text);
soundObject.setAttribute("hidden", true);
soundObject.setAttribute("autostart", true);
document.body.appendChild(soundObject);
}
window.onload = PlaySound;
</script>
<script runat="server" >
void Selection_Change(Object sender, EventArgs e)
{
label1.Text = SongList.SelectedItem.Value.ToString();
Response.Write(SongList.SelectedItem.Value);
}
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<asp:DropDownList id="SongList" AutoPostBack="True" OnSelectedIndexChanged="Selection_Change"
runat="server">
<asp:ListItem Selected="True" Value="Love Is All Around.mp3">
Love Is All Around.mp3</asp:ListItem>
<asp:ListItem Value="Om.mp3">Om.mp3</asp:ListItem>
<asp:ListItem Value="Nights In White Satin.mp3">
Nights In White Satin.mp3</asp:ListItem>
</asp:DropDownList>
<asp:Label ID="label1" Text="Om.mp3" runat="server" />
<input type="button" onclick="PlaySound()" value="Play Sound" />
【问题讨论】:
标签: asp.net audio drop-down-menu