只要我将标签添加到我的jQuery select2
,它就会中断并恢复为正常的HTML select
框。
这是我的代码(与this example完全相同):
$(document).ready(function() {
$("#tags").select2({tags:["red", "green", "blue"]});
});
如果我删除标签部分,它会再次起作用:
$(document).ready(function() {
$("#tags").select2();
});
答案 0 :(得分:7)
如果查看javascript控制台,您将看到以下错误消息:
错误:选项'标记'当附加到a时,不允许使用Select2
<select>
元素。
这意味着,当您想要使用&#39;标签&#39;选项,您必须将其应用于input:text
元素而不是select
。
JSFiddle with proof:http://jsfiddle.net/Y8Wc7/
答案 1 :(得分:7)
Select2 version 4.0.0现在允许将标记附加到 public class ImageGetterAsyncTask extends AsyncTask<String, Void, Drawable> {
URLDrawable urlDrawable;
public ImageGetterAsyncTask(URLDrawable d) {
this.urlDrawable = d;
}
@Override
protected Drawable doInBackground(String... params) {
String source = params[0];
return fetchDrawable(source);
}
@Override
protected void onPostExecute(Drawable result) {
// set the correct bound according to the result from HTTP call
urlDrawable.setBounds(0, 0, 0 + result.getIntrinsicWidth(), 0
+ result.getIntrinsicHeight());
// change the reference of the current drawable to the result
// from the HTTP call
urlDrawable.drawable = result;
// redraw the image by invalidating the container
URLImageParser.this.container.invalidate();
}
/***
* Get the Drawable from URL
* @param urlString
* @return
*/
public Drawable fetchDrawable(String urlString) {
try {
InputStream is = fetch(urlString);
Drawable drawable = Drawable.createFromStream(is, "src");
drawable.setBounds(0, 0, 0 + drawable.getIntrinsicWidth(), 0
+ drawable.getIntrinsicHeight());
return drawable;
} catch (Exception e) {
return null;
}
}
private InputStream fetch(String urlString) throws MalformedURLException, IOException {
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpGet request = new HttpGet(urlString);
HttpResponse response = httpClient.execute(request);
return response.getEntity().getContent();
}
}