java 对控件的显示隐藏,使用java脚本显示隐藏的ASP图像控件

How to hide asp image control using java script

. I tried following code but its not working. image is not visible when on change function is called.

javascript is at client side if I set visibility property of image control to false then can i make it visible through javascript?

What I have tried:

image control code:

javascript:

function previewFile() {

var preview = document.querySelector(''#'');

var file = document.querySelector(''#'').files[0];

document.getElementById("Image4").style.visibility = "visible"

var reader = new FileReader();

reader.onloadend = function () {

preview.src = reader.result;

}

if (file) {

reader.readAsDataURL(file);

} else {

preview.src = "";

}

}

解决方案

If you try to hide the Image asImage1.Visible = true;

in the server, the Image element will be completely removed from the DOM[^]. and you wont be able to control the visibility in javascript( client side).

try this, in c# to hide the element

Image1.Style.Add("display","none");

now the visibility functionality will work as mentioned in the Solution 1

Note: display:none removes the element from the place, allowing other elements to fill in that place where as

visibility:hidden leaves the element in the declared place of the page such that it will still occupies the space

HTML DOM Style visibility Property[^] where element will still occupy space when invisible

document.getElementById("Image4").style.visibility = "visible";

document.getElementById("Image4").style.visibility = "hidden";

HTML DOM Style display Property[^] where element will not occupy space when hidden

document.getElementById("Image4").style.display = "block";

document.getElementById("Image4").style.display = "none";

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值