是jQuery 1.3.2中的JQuery(..).html()越野车吗? [英] Is JQuery(..).html() buggy in jQuery 1.3.2?

查看:89
本文介绍了是jQuery 1.3.2中的JQuery(..).html()越野车吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此处的代码未返回预期的结果

The code here does not return what one expects:

jQuery('<div>Look here: [ jQuery0="null" ]</div>').html()

相反,您得到:

Look here: [ ]

有问题的jQuery源代码:

The jQuery source code in question:

html: function( value ) {
        return value === undefined ?
                (this[0] ?
                        this[0].innerHTML.replace(/ jQuery\d+="(?:\d+|null)"/g, "") :
                        null) :
                this.empty().append( value );
},

.replace背后的动机是什么?我没有时间讨论其余的jQuery,但是这样的代码让我想知道我是否应该在生产中完全使用jQuery.

What would be the motivation behind the .replace? I do not have time to go over the rest of jQuery, but code like this makes me wonder if I should use jQuery in production at all.

推荐答案

此代码是1.3.2中的新功能,而不是1.3.1中的新功能.在我看来,jQuery使用名称以"jQuery"开头的属性来存储元素上的数据,这是当您要求返回html时不向您公开的属性.

This code is new in 1.3.2, it wasn't in 1.3.1. It looks to me like jQuery uses attributes whose names start with "jQuery" to store data on elements, and this is its way of not exposing that to you when you ask for the html back.

这显然不是错误.作者打算在返回字符串之前删除该HTML.

It clearly isn't a bug. The author intended to remove that HTML before returning you the string.

这会影响您的代码吗?与任何库一样,您应在部署代码之前对其进行全面的测试.

Does this affect your code? As with any library, you should test your production code thoroughly before deploying it.

这篇关于是jQuery 1.3.2中的JQuery(..).html()越野车吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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