【问题标题】:How to make bootstrap radio buttons (aspx)如何制作引导单选按钮(aspx)
【发布时间】:2018-02-01 01:33:41
【问题描述】:

我正在尝试制作一种个人资料页面。我希望用户能够从 3 个主题中进行选择(它只会改变网站上页面的颜色)。但是,当单击单选按钮时,我不知道如何做到这一点。 这是我的代码:

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="panel-body">
  <div class="container">
     <form>
        <div class="radio">
            <label>
                <input type="radio" name="optradio">Blue
            </label>
        </div>
        <div class="radio">
            <label>
                <input type="radio" name="optradio">Red                  
            </label>
        </div>
        <div class="radio disabled">
            <label>
                <input type="radio" name="optradio">Wood
            </label>
        </div>
      </form>
      </div>
  </div>
</div>

问题是:如何使单选按钮实际执行某些操作? 编辑:我的错,我想使用实际的单选按钮而不是按钮。我已经删除了上面的代码并替换了它。

【问题讨论】:

  • 您希望在单击单选按钮时更改背景颜色,对吗?例如:红色第一,蓝色第二,绿色第三?
  • 单击单选按钮后,如果您不使用带有提交按钮的表单并且正在为每个用户保留主题,则可能需要进行 ajax 调用。然后就是用js来改变你的类了。

标签: html asp.net twitter-bootstrap


【解决方案1】:

function red() {
    document.getElementById("he").style.backgroundColor = "red";
}
        function blue() {
    document.getElementById("he").style.backgroundColor = "blue";
}
        function green() {
    document.getElementById("he").style.backgroundColor = "green";
}
<body id="he">
  <div class="panel-body">
      <div class="container">
       <form>
         <div class="radio" >
           <label>
            <input type="radio" name="optradio" onclick="blue();">Blue</label>
         </div>
         <div class="radio">
           <label>
            <input type="radio" name="optradio" onclick="red();">Red</label>
         </div>
         <div class="radio">
         <label>
           <input type="radio" name="optradio" onclick="green();">Green</label>
         </div>
         </form>
        </div>
    </div>
</body>

这就是你要找的对吗?

【讨论】:

  • 感谢您的评论,但它并没有改变背景的颜色。还有什么我应该做的吗?
  • 我可以在Tutorialpoint 游乐场看到颜色变化,但是当我尝试在 JSFiddle 上看到它时,它并没有发生。让我看看我缺少哪些导入。
  • JSFiddle Solution 也是如此。您需要确保的只是添加 CDN
  • 尽管我添加了导入,但似乎仍然不起作用。另外,什么是 CDN,如何添加?
  • 你把id="he"&lt;body&gt;&lt;body id="he"&gt; 了吗?
猜你喜欢
  • 1970-01-01
  • 2014-07-24
  • 1970-01-01
  • 2018-02-13
  • 1970-01-01
  • 1970-01-01
  • 2012-07-12
  • 2014-12-08
相关资源
最近更新 更多