使用jQuery模拟鼠标单击选择选项 [英] simulating mouse click on select option with jquery

查看:246
本文介绍了使用jQuery模拟鼠标单击选择选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我单击选择"选项时,我正在处理已更改"事件.

When I click on a Select option, I am handling the Changed event.

我想在代码中对此进行模拟,并使其与用户单击选项时的外观相同.

I want to simulate this in code, and have it LOOK THE SAME as when the user clicks on the option.

到目前为止,在选项上设置'selected'属性并不会与单击该属性时一样突出显示该属性.

So far, setting 'selected' attribute on the option does not highlight it the same as when you click on it.

我可以触发该选项的更改"并点击我的处理程序,但是列表中的选项没有被选中,就像单击一样.

I can trigger 'change' on the option and hit my handler, but the option on the list is not selected as if clicked.

建议?

更新: 查询选择代码可以正常工作-感谢您的答复.问题出在我的身上(当然).我在Jquery.Ajax Success:块之外有选择代码,所以我认为它正在工作,但是ajax响应代码正在处理它.

UPDATE: The query selection code works just fine - thanks for the responses. The problem was mine (of course). I had the selection code outside the Jquery.Ajax Success: block, so I think it was working, but the ajax response code was hosing it.

推荐答案

我正在使用jquery数据表插件ColumnFilterWidgets,我需要执行以下操作来执行过滤器操作(基于Elclanrs和Ben Foster的回答):

I was working with the jquery datatable plugin ColumnFilterWidgets and I needed to do the following to execute the filter action (based on answers from elclanrs and Ben Foster):

$("option").attr('selected', 'selected').parent().focus();
$("option").parent().change();

这篇关于使用jQuery模拟鼠标单击选择选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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