本帖最後由 carlkyo 於 2018-6-5 18:49 編輯

如果我想做到preselecte單或多個應該點寫
many thanks
唔用select2做簡單好多

TOP

有ching可以幫忙嗎
many thanks

TOP

本帖最後由 laputafish 於 2018-6-6 09:39 編輯

<select id="friends" multiple="multiple" >
    <option value="peter">Peter</option>
    <option value="john">John</option>
    <option value="mary">Mary</option>
</select>
<script>
...
$(document).ready(function() {
   $('#friends').select2({placeholder: 'Select ...'});
   $('#friends').val(['peter','john']).trigger('change'); // 選擇 John 及 Peter.
}
...
</script>
用左 select2(...), 可以唔洗再 .option(...) , 直接 .val(....).trigger('change')

TOP

本帖最後由 carlkyo 於 2018-6-7 09:21 編輯
Peter
    John
    Mary


...
$(document).ready(function() {
   $('#friends').select2({placehol ...
laputafish 發表於 2018-6-6 09:35


hi ching
option 係post過來用唔到
純HTML既情況下你既CODE絕對用到
我唔想個頁面太多CODE,所以
<select id="friends" multiple="multiple" ></select>裡面係吉既
many thanks

TOP