无法从WatiN在选择列表上触发jQuery change()事件 [英] Unable to fire jQuery change() event on selectlist from WatiN
本文介绍了无法从WatiN在选择列表上触发jQuery change()事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个选择框
<select id="myselectbox">
<option value='a'>First option</option>
<option value='b'>Second option</option>
</select>
还有jQuery
$('#myselectbox').change(function() {
...
});
还有WatiN测试
SelectList list = Browser.SelectList(Find.ById("myselectbox"));
list.Select("First option");
在IE中,这会更改选择框,但不会触发jquery事件处理程序.我知道IE中的change()事件处理程序周围存在许多问题.因此,我尝试在测试中添加一些内容以强制触发事件:
In IE, this changes the select box, but doesn't fire the jquery event handler. I am aware of the many issues surrounding the change() event handler in IE. So I have tried adding a number of things to the test to force the event to fire:
list.Blur();
list.Keypress('\r');
list.Click();
我还尝试在选择框之外单击以删除焦点,希望这会触发事件.
I also tried to click outside the select box to remove the focus, hoping this would fire the event.
有什么想法吗?
推荐答案
您可以手动触发该事件:
You could manually fire the event:
$('#myselectbox').change();
您要触发的其他JavaScript事件不会更改该值,因此它们不会触发change
事件.
The other JavaScript events you're firing don't change the value, so they won't fire the change
event.
这篇关于无法从WatiN在选择列表上触发jQuery change()事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文