当点击关闭按钮和点击建议文本与select2 [英] when click on close button and when click on suggestions text with select2
问题描述
我想检查用户是否点击select2关闭按钮,或只是触发了更改事件。这是我的select2输入:
<%= hidden_field_tag:query,params [:query],:id => query_txt%>
在我的coffeescript文件中:
$('#query_txt')。select2(
#select2 options here,ajax,initSelection ... etc
#
#
#
$(#query_txt)。关于change,(e) - >
if($(select2-search-choice-close)。click - >)
console.log点击关闭
)
问题是如果我点击建议文字我可以在我的控制台上看到点击关闭。
换句话说,如果您点击此图片中的 x / remove按钮:
>
如果您点击此图片中的建议文字,会出现相同的行为:
您可以在 http://jsfiddle.net/nqWNJ/9/
我的问题是
谢谢
您需要添加另一个点击时触发的事件。 $ queryTxt = $('#query_txt')#cache object
$ queryTxt.select2(
#select2 options here,ajax,initSelection ... etc
#
#
#
)
$ queryTxt.on'change',(obj) - >
console.log'clicked on close'if obj.removed
console.log'changed was triggered'
I want check if a user click on select2 close button or only it's triggered a change event. This is my select2 input:
<%= hidden_field_tag :query, params[:query], :id => "query_txt" %>
On my coffeescript file:
$('#query_txt').select2(
#select2 options here, ajax, initSelection...etc
#
#
#
$("#query_txt").on "change", (e) ->
if ($(".select2-search-choice-close").click ->)
console.log "click on close"
)
The problem is that if I click on suggestions text I can see the text "click on close" on my console.
In other words, If you click on x/remove button as in this image:
the same behavior happens if you click in suggestions text as in this image:
You can see a example code in http://jsfiddle.net/nqWNJ/9/
My question is how I can know when a user clicks on suggestions text or click on the close button.
Thank you
you need to add another event that will trigger on click.
$queryTxt = $('#query_txt') #cache object
$queryTxt.select2(
#select2 options here, ajax, initSelection...etc
#
#
#
)
$queryTxt.on 'change', (obj) ->
console.log 'clicked on close' if obj.removed
console.log 'change was triggered'
这篇关于当点击关闭按钮和点击建议文本与select2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!