JavaScript中的功能以在onclientclick按钮上显示图像 [英] function in javascript to show image on button onclientclick
问题描述
大家好,
我正在使用母版页,而不是从该母版页继承内容页.
然后我在内容页面中创建了一个javascript函数.但是它不能正常工作.意味着它在onclientclick按钮上显示图像.
图片会不断显示在页面上.
但是按钮点击事件的作用不大
代码是:
Hi All,
I am using the master page.and than inherit the content page from that master page.
and than i create a javascript function in content page.but it is not working properly .means it display image on button onclientclick .
the image is constantly show on page.
but the button click event dose,t working
The code is:
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<script language="javascript">
function abc() {
document.getElementById('ctl00_ContentPlaceHolder1_img').style.display = 'block';
}
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:Button ID="button1" runat="server" OnClientClick="abc(); return false;" Text="view image" />
<asp:image id="img" runat="server" ImageURL="~/loadingAnimation.gif" style="display:none;" />
</asp:Content>
所以请帮帮我.
在此先感谢.
so Please help me out this.
Thanks in Advance.
推荐答案
Rakesh是正确的.另一种方法是在asp:Button
标签的OnClientClick
上添加一个javascript代码.看看.
Rakesh is right. An alternative with this one is to add a javascript code on theOnClientClick
of yourasp:Button
tag. Take a look.
<asp:Button ID="button1" runat="server" OnClientClick="abc(); return false;" Text="view image" />
[更新]
我不知道您的按钮上有一个服务器端事件,您发布的代码是不同的.在这种情况下,为什么不只在按钮单击事件上设置img.Visible = true
,在页面加载中设置img.Visible = false
呢?
[Update]
I did''nt know you had a server side event on your button, the code you posted is different. In this case, why wont you just set img.Visible = true
on your button click event and img.Visible = false
on your Page Load.
原因:单击按钮时发生回发,并且自声明隐藏在标记中的图像,它将再次隐藏,因此闪烁.
解决方案:为什么不尝试使用html按钮:"<input id="button1" type="button" onclick="abc();" value="view image" />
"
Reason: When you click button postback happens and since you have declared the image as hidden in your markup, it becomes hidden again, hence the flickering.
Solution: Why don''t you give html button a try: "<input id="button1" type="button" onclick="abc();" value="view image" />
"
使用html按钮并将abc()方法放在按钮单击上.它不会呈现您的页面.
use html button and put the abc() method on button click. it will not rendered you page.
这篇关于JavaScript中的功能以在onclientclick按钮上显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!