Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 元素在函数中与此相同_Jquery - Fatal编程技术网

Jquery 元素在函数中与此相同

Jquery 元素在函数中与此相同,jquery,Jquery,我有jquery函数: function handleSplittingPrices() { var customerId = $(this).val(); loadSplittingPrices(customerId); } 我想用elem作为“this”执行它: var elem=$('…'); HandleSplitingPrices()您正在寻找: 请注意,elem是一个jQuery对象,而不是DOM元素,因此不需要在函数内部调用$。使用: 你不能。显然你不知道“这”是

我有jquery函数:

function handleSplittingPrices() {
    var customerId = $(this).val();
    loadSplittingPrices(customerId);
}
我想用elem作为“this”执行它:

var elem=$('…');
HandleSplitingPrices()您正在寻找:

请注意,
elem
是一个jQuery对象,而不是DOM元素,因此不需要在函数内部调用
$

使用:


你不能。显然你不知道“这”是干什么的

功能无手柄安装价格(elem){ var customerId=$(elem.val(); 分载价格(客户ID); }

变量元素=$('…'); 无手柄安装价格(elem)


哇。现在,这不是比试图定义整个面向对象编程概念更简单吗?

如果你想居高临下,你应该首先确保自己是正确的。
var elem=$('...');
handleSplittingPrices() <-- here elem will be this
handleSplittingPrices.call(elem);
handleSplittingPrices.call(elem);