小编Mob*_*baz的帖子

使用Bootstrap选择表单中的多个按钮

我有一组按钮,形成一个选择作为我的表单的一部分.

代码如下:

<div class="form-group">
    <div>
        <h4>Extras</h4>
    </div>
    <div class="radio-inline">               
         <input type="button" class="btn btn-default inline" name="extra" value="Garden" > 
         <input type="button" class="btn btn-default inline" name="extra" value="Balcony">  
         <input type="button" class="btn btn-default inline" name="extra" value="Parking">  
    </div>  
</div>
Run Code Online (Sandbox Code Playgroud)

但是,我想让选项不相互排斥,即你可以选择'花园'和'阳台' - 我想保留按钮样式.

有人能帮忙吗?

编辑:好的 - 现在有一些奇怪的事情 - 得到这个代码.

<div class="btn-group" data-toggle="buttons">
                      <label class="btn btn-default">
                        <input type="checkbox" name="garden" checked=""> Garden
                      </label>
                      <label class="btn btn-default">
                        <input type="checkbox"> Balcony
                      </label>
                      <label class="btn btn-default">
                        <input type="checkbox"> Parking
                      </label>
                    </div>
Run Code Online (Sandbox Code Playgroud)

当我使用bootply时,多选用户功能很有效 - 当我将它添加到我的页面时 - 它不起作用 - 有没有人知道它为什么会这样?以下是整个页面

<div class="container">
    <div class="row"> …
Run Code Online (Sandbox Code Playgroud)

html forms button twitter-bootstrap

5
推荐指数
1
解决办法
2万
查看次数

为某些字段禁用Bootstrap Validator

我是Bootstrap Validator和Jquery的新手,正在尝试完成某些工作。

我有一个表格,例如字段

<div class="form-group" id="price_container">
    <label for="price">Asking Price</label><input class="form-control" style="width: 50%;" type="text" id="price" name="price" >
</div>

<div class="form-group">
    <label for="title">Title</label>
    <input class= "form-control" type="text" name="title">
</div>
Run Code Online (Sandbox Code Playgroud)

我可以通过以下方式验证它:

 $('#multiform')
    .find('[name="list_type"]')
        .change(function(e) {
           $('#multiform').bootstrapValidator('revalidateField', 'price');
        })
        .end()
    .bootstrapValidator({
        message: 'This value is not valid',
        feedbackIcons: {
            required: 'fa fa-asterisk',
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        },
        fields: {
            price: {
                validators: {
                   notEmpty: {
                      message: 'The price is required and cannot be empty'
                   },
                   integer: {
                      message: 'You …
Run Code Online (Sandbox Code Playgroud)

javascript validation jquery twitter-bootstrap jqbootstrapvalidation

5
推荐指数
1
解决办法
2万
查看次数

从onchange事件处理程序中提取变量以用于其他函数

我有一个事件处理程序侦听下拉列表中的更改并设置变量的值.我已将变量声明为全局,即在任何函数之外,然后将值设置为更改.但是,一旦它发生了变化,我需要能够在其他函数中获取变量(不在even处理程序中).我如何从事件处理程序中"提取"它?我试图返回但没有运气 - 这是代码:

$(document).on('change', 'select#search_subject', function () {
    if ($('#sBar3').show()) {
        $('#sBar3').hide();
    }
    var subject = $('#search_subject>option:selected').text();
    var id = $('#search_subject>option:selected').val();
    ajaxSubject(subject, '#sBar3');
    return subject;
});
console.log(subject);   
Run Code Online (Sandbox Code Playgroud)

日志只显示'空字符串',我感到很困惑.如果可能的话,我不想重新编写代码以包含事件处理程序中的所有内容(那里有很多Google Map生成代码,这会让人感到痛苦) - 我只需要将事件处理器中的主题变量取出来有意义 - 谢谢

javascript variables jquery event-handling

1
推荐指数
1
解决办法
653
查看次数

如何用jquery添加div的副本?

我有一个div包含一些动态生成的下拉列表.

我想克隆它并将其添加到原始下面.原始代码是:

<div id="subjectselectiondiv" style="width:inherit;">
    <h4>Select the subjects that you are able to tutor</h4>
    <div id='choices'>
        <script type="text/javascript">
            var doc = document.getElementById("choices");
            var subj_div = document.createElement('div');
            subj_div.setAttribute('class', 'selectSearchBar');
            subj_div.innerHTML = '<select id="level'+counter+'" name="level'+counter+'" class="selectSearchBar"><?php echo "<option>Level</option>"; while($row = mysqli_fetch_array($result_level, MYSQLI_ASSOC)){echo "<option value=".$row['id'].">".$row['level']."</option>";}?></select><div id="subject'+counter+'" style="display:inline;">sBar2</div><div id="topic'+counter+'" style="display:inline;">sbar3</div>';
            doc.appendChild(subj_div);
        </script>
    <a href='#' class="more" onclick="Repeat()">Add another subject</a>
</div>
Run Code Online (Sandbox Code Playgroud)

我认为函数Repeat()可以用于:

function Repeat(){
    counter++;
    $('#choices').clone().appendTo('#subjectselectdiv');
    event.preventDefault();
}
Run Code Online (Sandbox Code Playgroud)

但这不起作用 - 我错过了什么吗?

谢谢

javascript jquery clone copy

1
推荐指数
1
解决办法
216
查看次数