Joh*_*ohn 3 javascript asp.net jquery asplinkbutton
我试图从按钮切换到超链接(上一篇文章),但无法让它工作,所以决定使用链接按钮代替.
在我正在使用的aspx页面中
<script type ="text/javascript">
function showImg(url)
{
$("#imagePreview").attr("src", url);
}
</script>
<div style="height:50px; margin-top:25px; margin-bottom:25px;">
<img id="imagePreview" alt="" width="30" height ="30"></img>
</div>
Run Code Online (Sandbox Code Playgroud)
然后在我正在使用的ascx页面中
<input type="button" onclick='javascript:showImg("<%# FieldValueString %>")' />
Run Code Online (Sandbox Code Playgroud)
这工作正常,当单击按钮时,图片显示在下面,但我想要一个链接按钮.
我已经在http://www.devmanuals.com/tutorials/ms/aspdotnet/linkbutton.html上尝试了这些例子,但没有喜悦,
我试过了
<asp:LinkButton
ID="LinkButton1"
runat="server"
Text="Preview"
Font-Bold="True"
ForeColor="Maroon"
PostBackUrl='javascript:showImg("<%# FieldValueString %>")' />
Run Code Online (Sandbox Code Playgroud)
但是当我点击按钮时没有任何反应我是否必须将任何代码添加到.cs文件中?
请帮忙
thaks
您使用的是不正确的属性.试试这个:
<asp:LinkButton
ID="LinkButton1"
runat="server"
Text="Preview"
Font-Bold="True"
ForeColor="Maroon"
OnClientClick='javascript:showImg("<%# FieldValueString %>"); return false;' />
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
244 次 |
| 最近记录: |