jquerymobile 表单在移动浏览器上无法按预期工作,但在桌面浏览器上工作?
我的 jqm 表单在移动浏览器(iPad 1 Safari、Android Dolphin)中无法正常工作,但在桌面浏览器(Chrome、Firefox、Safari 和 Win7 上的 IE9)中按预期工作时遇到问题。
该表单首先询问用户希望如何联系(电子邮件、短信和/或帖子),然后根据此选择更新所需的字段(通过validationEngine.js 插件进行验证)。
可以在此处查看该表单的示例。
该脚本的逻辑是,它检查复选框是否被选中(或取消选中),然后添加(或删除)一个类以使其成为必需的,如下所示。
$('body').delegate('#byEmail_label', 'click tap', (function(event) {
if (!$("#byEmail").is(":checked"))
{
$('#req_email').addClass('reqField');
$('#email').addClass("validate[required,custom[email]]");
}
else
{
$('#req_email').removeClass('reqField');
$('#email').removeClass("validate[required,custom[email]]").validationEngine('hide');
}
})
);
我在没有 .delegate() 的情况下 100% 工作,但是后来我无法通过 ajax 加载表单 - 添加 .delegate 后,一切都运行良好,除了在移动浏览器中。
有没有人经历过类似的事情,或者知道我如何才能让它发挥作用?
谢谢
I am having a problem with my jqm form not working properly in mobile browsers (iPad 1 Safari, Android Dolphin) but working as expected in desktop browsers (Chrome, Firefox, Safari & IE9 on Win7).
The form starts by asking the user how they would like to be contacted (email, sms, and/or post), then updates fields to be required based on this selection (validation is via the validationEngine.js plugin).
An example of the form can be seen here.
The logic of the script is that it checks to see if the checkbox is selected (or de-selected), then adds (or removes) a class to make it required as shown below.
$('body').delegate('#byEmail_label', 'click tap', (function(event) {
if (!$("#byEmail").is(":checked"))
{
$('#req_email').addClass('reqField');
$('#email').addClass("validate[required,custom[email]]");
}
else
{
$('#req_email').removeClass('reqField');
$('#email').removeClass("validate[required,custom[email]]").validationEngine('hide');
}
})
);
I had this working 100% without the .delegate(), but then I could not have the form load via ajax - after adding .delegate it all works well, except in mobile browsers.
Has anyone experienced something similar, or have any idea how I can get this working?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最后通过将所有 jquery 移出
并移入
ie 解决了我自己的问题:
现在我的头感觉好多了......不再把它敲在桌子上......
Finally fixed my own problem by moving all my jquery outside the
and into
ie:
Now my head feels better... no more banging it on the desk...
我在复选框和单选按钮方面也遇到了麻烦,这就是我使用的。可能有助于检查该值而不是是否已检查。
或
或
也许是这样的
I also had troubles with checkboxes and radios, this is what I used. Might help to check for the value instead of if it's checked.
or
or
Maybe something like this