如何将单选按钮更改为Bootstrap按钮

时间:2016-10-03 02:20:58

标签: javascript php css twitter-bootstrap

我正在尝试将PHP中的单选按钮更改为Bootstrap中的按钮。

(我还想摆脱页面底部的提交按钮并提交答案。)

enter image description here

此代码有效,但它使用单选按钮:

    <div id='javatbd<?php echo $myfname; ?>' class='col-xs-12 form-group answer-item radio-item radio' <?php echo $sDisplayStyle; ?> >
        <input
            class="radio"
            type="radio"
            value="<?php echo $code; ?>"
            name="<?php echo $name; ?>"
            id="answer<?php echo $name.$code; ?>"
            <?php echo $checkedState;?>
            onclick="if (document.getElementById('answer<?php echo $name; ?>othertext') != null) document.getElementById('answer<?php echo $name; ?>othertext').value='';checkconditions(this.value, this.name, this.type)"
            aria-labelledby="label-answer<?php echo $name.$code; ?>"
         />
        <label for="answer<?php echo $name.$code; ?>" class="control-label radio-label"></label> 
        <div class="label-text label-clickable" id="label-answer<?php echo $name.$code; ?>">
            <?php echo $answer; ?>
        </div>
    </div>
.
.
.
    <div class="col-xs-6 save-all text-right">
                <button type="submit" id="movesubmitbtn" value="movesubmit" name="movesubmit" accesskey="l" class="submit button btn btn-lg  btn-primary">Submit</button>
            </div>

我已尝试过此功能,但它没有发送价值。 enter image description here

 <div id='javatbd<?php echo $myfname; ?>' class='col-xs-12 form-group answer-item radio-item btn' <?php echo $sDisplayStyle; ?> >

       <div class="container-fluid">
             <input
                class="btn btn-primary btn-block"
                type="button"
                value="<?php echo $code; ?>"
                name="<?php echo $name; ?>"
                id="answer<?php echo $name.$code; ?>"
                <?php echo $checkedState;?>
                onclick="if (document.getElementById('answer<?php echo $name; ?>othertext') != null) document.getElementById('answer<?php echo $name; ?>othertext').value='';checkconditions(this.value, this.name, this.type)"
                aria-labelledby="label-answer<?php echo $name.$code; ?>"
            />
       </div>
    </div>

3 个答案:

答案 0 :(得分:0)

您可以使用Bootstrap按钮无线电组件使单选按钮看起来像普通按钮。

<div class="btn-group" data-toggle="buttons">
    <label class="btn btn-primary">
        <input type="radio" name="options" id="option1"> Option 1
    </label>
    <label class="btn btn-primary">
        <input type="radio" name="options" id="option2"> Option 2
    </label>
    <label class="btn btn-primary">
        <input type="radio" name="options" id="option3"> Option 3
    </label>
</div>

您可以在此处查看实时示例和其他选项 - http://www.tutorialrepublic.com/twitter-bootstrap-tutorial/bootstrap-stateful-buttons.php

答案 1 :(得分:0)

这很有用。谢谢!现在我将尝试删除按钮中间的O并删除Submit按钮,因此单击Boss将提交值。

<div class="btn btn-primary btn-block">
   <input
      class="radio"
      type="radio"
      value="<?php echo $code; ?>"
      name="<?php echo $name; ?>"
      id="answer<?php echo $name.$code; ?>"
      <?php echo $checkedState;?>
      onclick="if (document.getElementById('answer<?php echo $name; ?>othertext') != null) document.getElementById('answer<?php echo $name; ?>othertext').value='';checkconditions(this.value, this.name, this.type)"
      aria-labelledby="label-answer<?php echo $name.$code; ?>"
   />
  <label for="answer<?php echo $name.$code; ?>" class="control-label radio-label"></label>

Image of radio / buttons

答案 2 :(得分:0)

这很有效!非常感谢!现在,我将尝试删除“提交”按钮,并使单击的值提交值。我正试图减少页面上的空间。

Bootstrap Radio / buttons. It worked

<div class="btn-block" data-toggle="buttons">
    <label class="btn btn-primary btn-block">
       <input
          class="radio"
          type="radio"
          value="<?php echo $code; ?>"
          name="<?php echo $name; ?>"
          id="answer<?php echo $name.$code; ?>"
          <?php echo $checkedState;?>
          onclick="if (document.getElementById('answer<?php echo $name; ?>othertext') != null) document.getElementById('answer<?php echo $name; ?>othertext').value='';checkconditions(this.value, this.name, this.type)"
          aria-labelledby="label-answer<?php echo $name.$code; ?>"
       />
      <label for="answer<?php echo $name.$code; ?>" class="control-label radio-label"></label>

      <div class="label-text label-clickable" id="label-answer<?php echo $name.$code; ?>">
          <?php echo $answer; ?>
      </div>
</div>