如何将函数作为参数传递给$()? 例如
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 $()
答案 0 :(得分:0)
参考: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')