使用change()的选定单选选项无法与JQM(jQueryMobile)一起正常使用 [英] Selected Radio option using change() not working as expected with JQM (jQueryMobile)

查看:161
本文介绍了使用change()的选定单选选项无法与JQM(jQueryMobile)一起正常使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到了Radios和使用JQM(jQueryMobile)库的change()函数的一个奇怪问题.

I'm seeing a strange issue with Radios and the change() function using the JQM (jQueryMobile) lib.

单击单选按钮时,我得到的是以前的值,而不是新的值,如此处所示: http://jsfiddle. net/fSbk9/3/

When clicking the radio I get the previous value instead of the new value Shown here: http://jsfiddle.net/fSbk9/3/

,但它应该像这样执行,如下所示:
http://jsfiddle.net/N6qmr/10/
其中change()应该显示所选值而不是旧值.

but it should execute like this, shown here:
http://jsfiddle.net/N6qmr/10/
where the change() should show the selected value not the old value.

有什么想法吗?

更新:

以下是工作版本: http://jsfiddle.net/fSbk9/15/

推荐答案

这是一个非常有趣的行为.更改功能由JQM称为onclick,然后您将看到警报消息,并在警报消息上单击确定"后,将看到单选框的选定值将切换.因此,在更改完成之前就调用了该函数,因此该值是错误的.但是原因,嗯...我解决了:

It is a very interesting behavior. The change function is called onclick by JQM, then you see the alert message and after clicking ok on the alert message you will see that the selected value of the radiobox will switch. So the function is called before the change was done, and so the value is wrong. But the reason why, hmm... I solved it:

执行此操作:

alert($('input[name=first_radio]:checked').val());

请参阅此处: http://jsfiddle.net/fSbk9/6/

这篇关于使用change()的选定单选选项无法与JQM(jQueryMobile)一起正常使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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