Javascript:将asp.net按钮可见性设置为false

时间:2015-01-20 05:42:09

标签: javascript asp.net button

我无法使用javascript隐藏我的按钮,我的代码是这样的。 (我用图像作为按钮)

<img alt="" src="images/search-icon.png" width="16" height="16" style="display: inline;height:16px;cursor:pointer; width: 16px;" onclick="ViewLookUpPayment('<%=btnShowCorpCode.ClientID %>');" />

以下是我的javascript中的代码。

function ViewLookUpPayment(bShow)
{
 var button1 = document.getElementById(bShow);
    button1.style.visibility = "visible";
}

每次我点击图像时,都会弹出运行时错误

enter image description here

我无法理解为什么会出现运行时错误,有人可以帮我解决这个错误吗?

2 个答案:

答案 0 :(得分:0)

试试这个

<img alt="" src="images/search-icon.png" 
width="16" height="16" style="display: 
inline;height:16px;cursor:pointer; width: 16px;" 
onclick="ViewLookUpPayment('<%=btnShowCorpCode.ClientID %>');" />


function ViewLookUpPayment(obj)
{

    document.getElementById(obj).style.display = "block";
}

答案 1 :(得分:0)

你有没有设置&#39; id&#39;属性到图像标签?

可能是&#34; document.getElementById(bShow)&#34;返回&#39; undefined&#39;。尝试检查&#34; var button1&#34;是。(例如:console.log(button1)

相关问题