jQuery vs jQuery Mobile-脚本顺序重要吗? [英] jQuery vs jQuery Mobile - Does the script sequence matter?

查看:86
本文介绍了jQuery vs jQuery Mobile-脚本顺序重要吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道为什么,但是当我以不同的顺序包含脚本时,这似乎会引起一些问题.

I do not know why but it seems to cause some problem when i include the script in a different sequence.

这样的话:

    <script src="static/jquery.mobile-1.3.1.min.js"></script>
    <script src="static/jquery-1.9.1.min.js"></script>
    <script src="static/jquery-migrate-1.1.1.min.js"></script>

我的程序有效!小提琴也起作用: http://jsfiddle.net/yvonnezoe/MKfLU/4/ 但是jQuery mobile的css主题在我的Web应用程序上不再起作用.

my program works! Fiddle works too : http://jsfiddle.net/yvonnezoe/MKfLU/4/ but the css theme for jQuery mobile doesnt work anymore on my web app.

这样的话:

    <script src="static/jquery-1.9.1.min.js"></script>
    <script src="static/jquery-migrate-1.1.1.min.js"></script>
    <script src="static/jquery.mobile-1.3.1.min.js"></script>

它不起作用,甚至在Fiddle上也为变量"textInput"提供了"undefined": http ://jsfiddle.net/yvonnezoe/7NZzr/

It doesn't work and gave me "undefined" for variable "textInput", even on Fiddle too: http://jsfiddle.net/yvonnezoe/7NZzr/

有人可以告诉我为什么吗? :(

Can someone tell me why? :(

推荐答案

要了解此问题,您需要了解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();

这篇关于jQuery vs jQuery Mobile-脚本顺序重要吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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