Javascript 原型相当于jquery函数,无需美元

Javascript 原型相当于jquery函数,无需美元,javascript,prototypejs,Javascript,Prototypejs,我有一个站点同时具有jQuery1.8和Prototype 2,使用$(美元符号)似乎调用jQuery,但我想调用Prototype(从控制台)。特别是要做这样的事情: 原型中是否有类似jQuery()函数的等价物?原型不是像jQuery那样的单个对象,因此不能这样调用它 滑动分页 此时,有一个jQuery对象正在引用DOM。但是,如果您试图像实际的DOM对象一样使用它,它将无法工作 // This won't work jq.className = ""; // This works beca

我有一个站点同时具有jQuery1.8和Prototype 2,使用$(美元符号)似乎调用jQuery,但我想调用Prototype(从控制台)。特别是要做这样的事情:


原型中是否有类似jQuery()函数的等价物?

原型不是像jQuery那样的单个对象,因此不能这样调用它

滑动分页 此时,有一个jQuery对象正在引用DOM。但是,如果您试图像实际的DOM对象一样使用它,它将无法工作

// This won't work
jq.className = "";
// This works because it's referencing the function inside jQuery
jq.removeClass();
请注意,如果需要,jQuery可以提供实际的DOM元素,但这不是默认行为

原型 您需要将原型视为使基础Javascript比对象更好。一个很好的例子是。
对象
对象已经存在于Javascript中,Prototype只是用另一个函数扩展它。当您看到Prototype的行为类似于jQuery时,几乎总是因为Prototype扩展了已经存在的东西

// This is a DOM reference
var pro = $('id'); // equivalent to document.getElementById('id');
pro.className = "";
// But there's no base Prototype object so this fails
pro.isUndefined();
// This is correct
Object.isUndefined(pro);

请看一看。您必须使用jQuery.noconflict才能将
$
符号用于其他用途。Prototype中没有这样做的功能,因为Prototype修改JavaScript语言中的全局Prototype(小p)对象来完成它的任务。因此
if(typeof object.isUndefined==“function”)
表示它是一个原型扩展对象:)
// This is a DOM reference
var pro = $('id'); // equivalent to document.getElementById('id');
pro.className = "";
// But there's no base Prototype object so this fails
pro.isUndefined();
// This is correct
Object.isUndefined(pro);