【发布时间】:2023-04-02 14:47:01
【问题描述】:
嗯,我知道我的标题有点混乱。我会在下面用例子清楚地说明。
<asp:ImageButton ID="imgButton" NavigateUrl="~/Presentation/Resources/Images/addFile.png" runat="server" />
在html中,上面的控件会呈现为
<input type="image" name="imgButton" id="imgButton" src="../../Resources/Images/addFile.png" style="border-width:0px;">
我注意到,它会将 src 从“~”转换为“../../”。它会自动排列文件级别。
所以在 javascript 中,我想用这个 url 设置它的控件:
~/Presentation/Resources/Images/PDF.png
不幸的是,在 html 中它将被呈现为
<input type="image" name="imgButton" id="imgButton" src="~/Presentation/Resources/Images/addFile.png" style="border-width:0px;">
我的问题是,如果我想用“~”获得“../../”相对路径,我应该写什么? 这个我试过了,就是不明白。
<script type="javascript">
document.getElementById("<%= imgButton.ClientID %>").src =
"~/Presentation/Resources/Images/PDF.png";
</script>
【问题讨论】:
-
对于 Razor,请参阅 stackoverflow.com/questions/8574237/…
标签: c# javascript jquery asp.net html