我正在尝试基于#var = 1`(或2、3或4)中的变量更改aspx asp.net c#页面上图像的imageurl
不幸的是,我对javascript一无所知。谁能指出我一个可以通过实施学习的基于新手的脚本?
参考方案
您的问题非常含糊,因此我不确定您到底需要什么...我只是要编写一些代码,看看它是否接近标准
尝试类似
<img id="someUniqueIdYouMakeUp">
<script type="text/javascript">
theImage = document.getElementById("someUniqueIdYouMakeUp");
if(window.location.hash == "#var=1")
{
theImage.src = "/some/image.jpg";
}
else if(window.location.hash == "#var=2")
{
theImage.src = "/some/other/image.jpg";
}
</script>
编辑:根据您的评论,即使页面加载后哈希值发生变化,您仍在寻找要更新的图像。为此,您将需要类似于以下代码:
var updateImageWhenHashChanges = function()
{
theImage = document.getElementById("someUniqueIdYouMakeUp");
if(window.location.hash == "#var=1")
{
theImage.src = "/some/image.jpg";
}
else if(window.location.hash == "#var=2")
{
theImage.src = "/some/other/image.jpg";
}
// Tell the window to call updateImageWhenHashChanges() again in 500 miliseconds:
window.setTimeout(updateImageWhenHashChanges,500);
}
updateImageWhenHashChanges();
有关更多信息,请阅读有关window.setTimeout的信息。
javascript popupwindow之后的行如何工作? - javascript好的,我有一个来自后面代码的方法,可以创建一个popupwindow。然后有一行代码要在那之后执行,我想知道那行代码何时执行,是在使用popupwindow之后执行还是在创建popupwindow之后执行?例如:void exPopupWindowMethod() { string scr = "window.open('exampleP…
ddl在服务器中未更新-asp.net - javascript我在ASP.NET c#上工作。我有一个DropDownList。 (runat =“ server”)在$ {document).ready上,我更新了它的值:$(document).ready(function () { document.getElementById("ddl").value = "abc"; ……
单击选项卡链接时,请专注于每个引导选项卡中的First asp:textbox - javascript我是开发的新手,并开始开发简单的asp.net应用程序。我正在使用每个都有一些asp标签和文本框的bootstrap选项卡。单击该选项卡时,我要重点关注选项卡内容中的第一个文本框。我搜索了各种答案,但都是针对输入字段的(exp:输入type =“ text”)。找不到适用于ASP文本框的任何内容。任何帮助将不胜感激。谢谢 javascript参考方案 ASP…
ASP.NET-如何更改JSON序列化的方式? - javascript我正在使用ASP.NET通过以下查询返回Json文件:public ActionResult getTransactionTotals(int itemID) { DBEntities db = new DBEntities(); var query = from trans in db.Transactions // Linq query removed …
ASP.NET MVC中应为DataTable返回哪种数据? - javascript我想为DataTable中的每个页面创建动态加载信息。我正在尝试遵循以下示例:https://www.datatables.net/manual/server-sidehttps://www.datatables.net/manual/data来自示例的代码:$('#example').DataTable( { serverSide: t…