jQuery Mobile - 动态创建表单元素 [英] jQuery Mobile - Dynamically creating form elements

查看:31
本文介绍了jQuery Mobile - 动态创建表单元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个面向 iOS 设备的网络数据库驱动的离线网络应用.我正在尝试使用 jQuery Mobile,但在创建各种表单时遇到问题.

I'm creating a web-database driven offline web-app targeted at iOS devices. I'm trying to use jQuery Mobile, but I have a problem in creating the various forms.

表单选项取自数据库查询,因此它们会在页面加载后插入到页面中,因此不会发生jQuery-Mobilification".快速浏览一下源代码,在这个阶段似乎没有任何明显的方法来调用它(当然它是一个 alpha 版本,我认为这将是一个相当普遍的请求,所以我希望它将会来).我可以采取某种解决方法来做到这一点吗?我对单选按钮、复选框和选择列表特别感兴趣.

The form options are taken from a database query, so they are inserted into the page after it has loaded, so the "jQuery-Mobilification" doesn't happen. Taking a quick look through the source, there doesn't seem to be any obvious way to call into this at this stage (of course it's an alpha release, and I think this would be a reasonably common request, so I'm hopeful it will come). Is there some kind of workaround I can put in to do this? I'm particularly interested in radio buttons, check boxes and select lists.

推荐答案

这在未记录的内部结构中很混乱,但以下对我有用:

This is messing around in undocumented internals, but the following is working for me:

$("#some-div").load("/html/fragment/", 
                    function() { 
                      $(this).find("input").customTextInput();  
                    });

按钮、复选框等有等价的方法

There are equivalent methods for buttons, checkboxes etc.

查看 _enchanceControls [sic] 方法rel="nofollow">http://code.jquery.com/mobile/1.0a1/jquery.mobile-1.0a1.js.

Have a look at the _enchanceControls [sic] method in http://code.jquery.com/mobile/1.0a1/jquery.mobile-1.0a1.js.

1.0Alpha2 的更新:正如在使用库的内部结构时可以预期的那样,这在最新版本中不再有效.将 customTextInput() 更改为 textinput() 修复了一点,但由于某种原因,主题并未完全应用.我们被警告...

Update for 1.0Alpha2: As can be expected when playing around with the internals of a library, this no longer works in the latest version. Changing customTextInput() to textinput() fixes it a bit, but the theme isn't fully applied for some reason. We were warned...

这篇关于jQuery Mobile - 动态创建表单元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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