如何将函数作为参数传递给 $()?例如
function autoplace(map){
// do something with map
};
var map = "Wassup";
$(autoplace(map)); // how to pass a function which takes a parameter, as a paramter to $()
如何将函数作为参数传递给 $()?例如
function autoplace(map){
// do something with map
};
var map = "Wassup";
$(autoplace(map)); // how to pass a function which takes a parameter, as a paramter to $()
参考:http ://api.jquery.com/jQuery/
$()
在不同的情况下接受不同类型的参数。
所以重点应该是您的autoplace()
函数返回的内容。然后将返回的内容传递给$()
例子:
function autoplace(map) {
var mapSelector = '#map_' + map,
$map = $(mapSelector);
// do something with map
// return something that's suitable for $()
// Just an example
return mapSelector; // In this example, mapSelector ends up being '#map_Wassup'
}
var $myMap = $( autoplace('Wassup') );
// The result will be equivalent to $('#map_Wassup')