[英]how to set visible property for div in javascript
I cannot able to access control in the below way 我无法通过以下方式访问控制
document.getElementById("_ctl0_ContentPlaceHolder1_divDocSearch").style.visibility = 'visible';
but i can able to access as 但我可以访问
var div = document.getElementById("_ctl0_ContentPlaceHolder1_divDocSearch");
div.style.visibility = 'visible';
How to access with above line, is there any toggle property available for this ? 如何使用上面的行进行访问,对此是否有任何切换属性可用?
Try 尝试
div.style = 'display:none';
to hide the div. 隐藏div。 and thus
因此
div.style = 'display:inline';
// or block, or whatever you need. //或阻止,或者您需要的任何东西。
to display the div. 显示div。
EDIT: 编辑:
Just foudn this: http://www.w3schools.com/css/css_display_visibility.asp 只是这样: http : //www.w3schools.com/css/css_display_visibility.asp
so it looks like you can do 所以看起来你可以做
div.visibility = 'hidden';
You can create a function like below 您可以创建如下功能
function toggle(obj){
if(obj.style.visibility == "visible")
obj.style.visibility = 'hidden';
else
obj.style.visibility = 'visible';
}
And then call them on the each element using toggle(object)
; 然后使用
toggle(object)
在每个元素上调用它们;
尝试这个:
document.getElementById("<%= divDocSearch.ClientID %>").style.display = 'none';
You can call the below function on click of all those divs passing in the id of the particular div being clicked. 您可以在所有这些div的点击中调用以下函数,并传入要点击的特定div的ID。 It finds all divs by using document.getElementsByTagName and hides them.
它使用document.getElementsByTagName查找所有div并隐藏它们。 Then it again makes visible the div whose id is passed
然后它再次使传递其ID的div可见
function showdiv(divid) {
divs = document.getElementsByTagName("div");
count=divs.length;
for(i=0;i<count;i++) {
divs[i].style.visibility="hidden";
}
document.getElementById(divid).style.visibility="visible";
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.