我希望动态地将select2添加到标记<select id="test" class="select2"></select>
。 E.g
<select id="test" class="select2"></select>
<button onclick="applySelect2()">Click me</button>
<script type="text/javascript">
function applySelect2() {
//code witch will aplly select2 for <select id="test" class="select2"></select>
//Please help
}
</script>
答案 0 :(得分:1)
首先你需要jQuery库,比这样的东西应该有帮助:
<select id="test" class="select2"></select>
<button id="myButton">Click me</button>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
<script>
jQuery(function($) { // DOM READY
$('#myButton').click(function(){
$("#test").select2();
});
});
</script>
或类似于您的示例:
jQuery(function($) { // DOM READY
function applySelect2() {
//code
}
$('#myButton').click(function(){
applySelect2();
});
});
答案 1 :(得分:-1)
// controller
app.controller('AppoimentCtrl', ['appointments', function (appointments) {
this.appoimentList = appointments;
}]);