我有
var sanmigBottle = document.createElement('sanmigBottle');
sanmigBottle.id="sanmigBottle";
sanmigBottle.width="25%";
sanmigBottle.src='sanmigbottle.png';
sanmigBottle.onmousedown="showLibraryInfo()" ;
sanmigBottle.ontouchstart="showLibraryInfo()" ;
sanmigBottle.align = "middle";
sanmigBottle.style= "-webkit-transform: rotate(350.77259795507035deg) translateZ(0px);'";
它加载我的html,但是我想隐藏它,我想要一个触发器来显示。当我输入时,
sanmigBottle.style.visibility="hidden";
它不起作用。我怎样才能做到这一点?我是JS新手,谢谢。
答案 0 :(得分:0)
你应该使用
sanmigBottle.style.display = 'none';
答案 1 :(得分:0)
您必须将display
设置为none
:
sanmigBottle.style.display="none";
然后再次将其设置为block
或其他内容以使其再次可见:
sanmigBottle.style.display="block";
答案 2 :(得分:0)
首先检查图像的状态:
function showhide() {
var img = document.getElementById('someimage');
if (img.style.visibility === 'hidden') {
// Currently hidden, make it visible
img.style.visibility = "visible";
} else {
// Currently visible, make it hidden
img.style.visibility = "hidden";
}
}
然后应用可见性。
答案 3 :(得分:-1)
尝试使用Jquery
//create element
var sanmigBottle = $('<img id="sanmigBottle" width="25%" src='sanmigbottle.png' onmousedown="showLibraryInfo()" ontouchstart="showLibraryInfo()" align = "middle" style= "-webkit-transform: rotate(350.77259795507035deg) translateZ(0px);"/>');
//add to document and store object in context
var context = sanmigBottle.appendTo($('Document'));
//hide object
context.fadeOut();