09.28《锋利的jQuery》复习盘点一

..遇到的bug:

一、TypeError:document.on is not a function

原因:①The problem may be if you are using older version of jQuery. Because older versions of jQuery have 'live' method instead of 'on'.

②Check your jquery version, it should be at least 1.7 for $(document).on() to work.

二、jQuery 3.1.0 incompatible with jQuery Mobile?

09.28《锋利的jQuery》复习盘点一_第1张图片

The page above doesn't render mobile styles; it just looks like plain html.When I use 3.1.0 the console says: TypeError: a.event.props is undefined.

原因:JQM officially only supports JQuery up to 2.1.x(jQuery 1.8 - 1.11 / 2.1)You may even run into problems if you're combining JQM with JQuery 2.2.x See the official site:jquerymobile.com- You can also find more information on the issue on their github page:github.com/jquery/jquery-mobile/issues–mpf82

其他补充:

如果一个页面只对应手机端的话,用jQuery 2.x比jQuery 1.x好,因为没有对IE低版本的额外支持。同时,你还可以选择取消掉一些项目需求里不包含的内容,来编译出来你自己需要的版本,以此压缩jQuery的大小;

如果是要做响应式的话,为了全浏览器兼容,只有用jQuery 1.x的最新版了。

移动端更合适用zepto.(之后学习).

三、表单验证插件validation插件和metadata插件

按书本写,用jquery.metadata.js进行验证,结果失败了。通过查看jquery.validate.js源码,如下图:

09.28《锋利的jQuery》复习盘点一_第2张图片

可以看出空格十分重要,将代码改成如下图:

09.28《锋利的jQuery》复习盘点一_第3张图片

然后页面就可以成功验证了!

你可能感兴趣的:(09.28《锋利的jQuery》复习盘点一)