当点击关闭按钮和点击建议文本与select2 [英] when click on close button and when click on suggestions text with select2

查看:660
本文介绍了当点击关闭按钮和点击建议文本与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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆