div风格:隐藏标签占用空间

时间:2011-09-06 12:45:59

标签: html html5

我有问题。我有两个HTML按钮,我想一次显示一个。我的代码工作正常,但问题是空间。在GUI中,存在两个按钮的空间,这是不可接受的。我想将两个按钮放在同一个位置。

代码是:

function searchWithin(id)
{
    if(document.getElementById("searchwithin").checked)
     {
     document.getElementById('searchwithin_'+id+'_searchButton').style.visibility="visible";
     document.getElementById(id+'-form-submit').style.visibility="hidden";
     }
     else
     {
         document.getElementById('searchwithin_'+id+'_searchButton').style.visibility="hidden";
         document.getElementById(id+'-form-submit').style.visibility="visible";
     }
}

<g2:button style="visibility:visible;" id="${g2:escapeXml(componentId)}-form-submit" name="submitButton" type="submit" value="Search" bamId="${searchBarBam}" actionName="${action}" inputClass="p-userSearchButton" />&nbsp;

<input style="visibility:hidden;" type="button"  class="p-userSearchButton" name ="searchinresult" id="searchwithin_${componentId}_searchButton" value="Search Within" onClick="javascript:($C('${componentId}')).filterBySearchWithIn('${searchBarBam}','${componentId}-form-text');"></input>

我需要改变它:

document.getElementById('searchwithin_'+id+'_searchButton').style.display="none";
     document.getElementById(id+'-form-submit').style.display="true";

<g2:button style="display:true;" 
           id="${g2:escapeXml(componentId)}-form-submit" 
           name="submitButton" 
           type="submit" 
           value="Search" 
           bamId="${searchBarBam}" 
           actionName="${action}" 
           inputClass="p-userSearchButton" />&nbsp;

<input style="display:none;" 
       type="button"  
       class="p-userSearchButton" 
       name ="searchinresult" 
       id="searchwithin_${componentId}_searchButton" 
       value="Search Within" 
       onClick="javascript:($C('${componentId}')).filterBySearchWithIn('${searchBarBam}','${componentId}-form-text');"></input>

但它不起作用。

1 个答案:

答案 0 :(得分:6)

您希望display: none;不是visibility: hidden

修改

在您编辑的代码中,您使用display: true来显示按钮,但正确的语法是:display: inline。有关更多显示选项的视图:w3schools.com/css/css_display_visibility.asp

如果这不能解决您的问题,请更清楚地定义您的问题完全