2014-09-11 42 views

回答

0

使用「佔位」選項,就像這樣:無需在JavaScript中指定佔位符

$(element).select2(placeholder: 'select one option', ** other options here); 
8

你也可以做這樣的事情的元素。

<%= f.collection_select :method, Model.all, :id, :name, 
{include_blank: true}, data: {placeholder: 'Choose Model'}, class: 
"select2"%> 

假設你已經在你的JavaScript文件的某處用select2初始化了這個元素。