除非我連續單擊了兩次按鈕,否則該函數將完美地執行。爲什麼我必須點擊兩次按鈕才能工作,我該如何解決這個問題?
function hideable(id) {
var e = document.getElementById(id);
if (e.style.display == 'inline-block')
e.style.display = 'none';
else
e.style.display = 'inline-block';
}
<img class="user_upload" src="upload/0000000000.gif" alt="1024 KB, 500x309" title="1024 KB, 500x309" id="0000000000">
<span id="hide_image" onclick="hideable('0000000000');">hide image</span>
編輯:對不起,我應該已經指定。下面是我已經使用CSS,但它仍然當你標記這個問題jQuery
你可以做同樣的事情在jQuery的簡單很多不工作(即使inline-block的)
img.user_upload {
height: 75px; display: inline-block; float: left;
margin: 0px 20px 10px 0px;}
只需在你的''標籤中添加**'style =「display:inline-block」'**。它會工作完美。 **例如**'' – prog1011 2014-10-01 11:41:55