且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

jQuery vs jQuery Mobile-脚本顺序重要吗?

更新时间:2023-12-05 08:21:40

要了解此问题,您需要了解jQuery Mobile的工作原理.

To understand this problem you need to understand how jQuery Mobile works.

在第二个示例中,初始化顺序不是问题.如果这是一个问题,那么所有这些元素都不会被设置样式.在您的情况下,您所不知道的是,当jQuery Mobile样式形成元素时,它会更改其DOM结构.因此,按钮和输入元素不再像您未设置样式的第一个示例中的相同.

Initialization order is not a problem in your second example. If it were a problem all those elements would not be styled. In your case, what you dont know is, when jQuery Mobile styles form elements it changes their DOM structure. So button and input elements are no longer at the same place like in your non-styled first example.

这是对jsFiddle的修复: http://jsfiddle.net/FmPPW/

This is a fix to your jsFiddle: http://jsfiddle.net/FmPPW/

更改此:

$('.TextInput').empty();
textInput = $(this).prev('.TextInput').val();

对此:

$('.TextInput').empty();
textInput = $(this).parent().prev().find('.TextInput').val();