簡體   English   中英

如何使按鈕切換的文本顯示在按鈕旁邊,而不是出現在新行上?

[英]How do I make the text my button toggles to appear right next to my button instead of on a new line?

這是我的代碼

<script type="text/javascript">

function toggle(obj) {
      var obj=document.getElementById(obj);
      if (obj.style.display == "block") obj.style.display = "none";
      else obj.style.display = "block";
}

<body>

<button type="button" style="width: 150px; height: 50px;"
onClick="toggle('miniDisplay')"> minicom </button>
<div id="miniDisplay" style="display:none;">

<p style="text-align:center;">connect to minicom and display</p></div>
</body>

當前,文本在按鈕所在的位置下方顯示一行。 我希望它顯示在同一行上。 我知道它是居中對齊的,它位於另一行按鈕的下方。

在您的JavaScript中將“阻止”更改為“內聯阻止”。

您的div是一個塊級元素,這意味着它將擴展以占據其容器的整個寬度。 改為將其更改為inline-block。

function toggle(obj) {
      var obj=document.getElementById(obj);
      if (obj.style.display == "inline-block") obj.style.display = "none";
      else obj.style.display = "inline-block";
}

jsFiddle示例

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM