选择所需属性

时间:2016-05-05 04:52:41

标签: twitter-bootstrap validation contact-form required

如何制作所需的选择表格?我试过把#34; required"但它没有用。

<div class="form-group">
    <label for="sel2">How many years have you been trading *</label>
    <select  class="form-control" id="sel2" required>
        <option>Please select one</option>
        <option>Start Up</option>
        <option value="1-2">1-3</option>
        <option value="3-4">3-4</option>
        <option value="5more">5 or more</option>
     </select>
</div>

同样对于这个,我刚从一个网站得到这个,我下载了zip文件,但我需要添加一个必需的属性

<div class="form-group">
    <label>Country *</label><br>
    <div id="basic" data-input-name="country" required></div>
</div>


 <script>
$('#basic').flagStrap();

$('#origin').flagStrap({
    placeholder: {
        value: "",
        text: "Country of origin"
    }
});

$('#options').flagStrap({
    countries: {
        "AU": "Australia",
        "GB": "United Kingdom",
        "US": "United States"
    },
    buttonSize: "btn-sm",
    buttonType: "btn-info",
    labelMargin: "10px",
    scrollable: false,
    scrollableHeight: "350px"
});

$('#advanced').flagStrap({
    buttonSize: "btn-lg",
    buttonType: "btn-primary",
    labelMargin: "20px",
    scrollable: false,
    scrollableHeight: "350px",
    onSelect: function (value, element) {
        alert(value);
        console.log(element);
    }
});
</script>

1 个答案:

答案 0 :(得分:2)

必需不在这里,因为你没有在所有选项中设置值。前两个选项中的值。

<link href="view/css/flags.css" rel="stylesheet">

<select  class="form-control" id="sel2" required>
       <option value="">Please select one</option>
       <option  value="startup">Start Up</option>
       <option value="1-2">1-3</option>
       <option value="3-4">3-4</option>
       <option value="5more">5 or more</option>
 </select>

<script>
$('#basic').flagStrap();

$('#origin').flagStrap({
    placeholder: {
        value: "",
        text: "Country of origin"
    }
});

$('#options').flagStrap({
    countries: {
        "AU": "Australia",
        "GB": "United Kingdom",
        "US": "United States"
    },
    buttonSize: "btn-sm",
    buttonType: "btn-info",
    labelMargin: "10px",
    scrollable: false,
    scrollableHeight: "350px"
});

$('#advanced').flagStrap({
    buttonSize: "btn-lg",
    buttonType: "btn-primary",
    labelMargin: "20px",
    scrollable: false,
    scrollableHeight: "350px",
    onSelect: function (value, element) {
        alert(value);
        console.log(element);
    }
});
</script>