Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/431.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在JavaScript中更改图像可见性?_Javascript_Asp.net_Visibility_Onmouseover_Onmouseout - Fatal编程技术网

如何在JavaScript中更改图像可见性?

如何在JavaScript中更改图像可见性?,javascript,asp.net,visibility,onmouseover,onmouseout,Javascript,Asp.net,Visibility,Onmouseover,Onmouseout,我试过了,但没有成功: JS: function Hide() { alert('Hide'); document.getElementById('I').style.visibility = 'none'; } function show() { alert('Show'); document.getElementById('I').style.visibility = 'visible'; } <asp:LinkButton ID="LinkBu

我试过了,但没有成功:

JS:

function Hide() {
    alert('Hide');
    document.getElementById('I').style.visibility = 'none';

}

function show() {
    alert('Show');
    document.getElementById('I').style.visibility = 'visible';

}
<asp:LinkButton ID="LinkButton1" onmouseover="show()" onmouseout="Hide()" runat="server">Mouse Here</asp:LinkButton>

<asp:Image Visible="false" ImageUrl="~/Images/V.png" ID="I" runat="server" />
function Hide() {
    alert('Hide');
    document.getElementById('I').style.display = 'none';
        
}

function show() {
    alert('Show');
    document.getElementById('I').style.display = 'block';
       
}
代码隐藏:

function Hide() {
    alert('Hide');
    document.getElementById('I').style.visibility = 'none';

}

function show() {
    alert('Show');
    document.getElementById('I').style.visibility = 'visible';

}
<asp:LinkButton ID="LinkButton1" onmouseover="show()" onmouseout="Hide()" runat="server">Mouse Here</asp:LinkButton>

<asp:Image Visible="false" ImageUrl="~/Images/V.png" ID="I" runat="server" />
function Hide() {
    alert('Hide');
    document.getElementById('I').style.display = 'none';
        
}

function show() {
    alert('Show');
    document.getElementById('I').style.display = 'block';
       
}
鼠标点击这里
我添加警报只是为了检查此功能是否处于活动状态,并且确实如此

有什么建议吗


谢谢

可见性
更改为
隐藏

function Hide() {
    alert('Hide');
    document.getElementById('I').style.visibility = 'hidden';

}
在更正和回答问题的同时,最好使用
display
来代替
show/hide
元素,这样更有效

display:none
表示元素根本不会出现在页面上,不会为其分配空间

可见性:隐藏
元素不可见,但在页面上为其分配了空间

示例:

function Hide() {
    alert('Hide');
    document.getElementById('I').style.visibility = 'none';

}

function show() {
    alert('Show');
    document.getElementById('I').style.visibility = 'visible';

}
<asp:LinkButton ID="LinkButton1" onmouseover="show()" onmouseout="Hide()" runat="server">Mouse Here</asp:LinkButton>

<asp:Image Visible="false" ImageUrl="~/Images/V.png" ID="I" runat="server" />
function Hide() {
    alert('Hide');
    document.getElementById('I').style.display = 'none';
        
}

function show() {
    alert('Show');
    document.getElementById('I').style.display = 'block';
       
}
希望这有帮助。

您的代码

document.getElementById('I').style.visibility='none'

应该是错的吗

document.getElementById('I').style.visibility='hidden'

还要记住,将“图元可见性”设置为“隐藏”将隐藏图元,但仍会占用屏幕上的空间

如果不希望元素在隐藏时占用空间,则必须使用
display:none

document.getElementById('I').style.display='none'

然后,您可以使用


document.getElementById('I').style.display='block'

显示:如果希望元素不占用空间,则显示无<代码>可见性:隐藏
,用于确定是否仍希望元素占用空间。看起来您将两者混合在一起。您可以使用样式显示:也没有。好的,谢谢!但是它只在没有
属性Visible=“false”
的情况下工作,并且尝试在
处进行更改!iPostBack
,但它不工作…好的,谢谢!但是它只在没有可见的(
Atributes Visible=“false”
的情况下工作,并且尝试在!iPostBack,但它不起作用。。。当我看不到图像时,我需要页面启动。当页面连接到母版页时,我也有问题