Javascript 调用具有多个值的函数
如何仅在一种模式下调用所有选项?例如:隐藏(“房子、建筑物、衣服”)或隐藏(“房子”、“建筑物”、“衣服”)。。。有可能吗Javascript 调用具有多个值的函数,javascript,function,google-maps,hide,show,Javascript,Function,Google Maps,Hide,Show,如何仅在一种模式下调用所有选项?例如:隐藏(“房子、建筑物、衣服”)或隐藏(“房子”、“建筑物”、“衣服”)。。。有可能吗 // == shows all markers of a particular category and ensures the checkbox is checked function show(category) { for (var i=0; i<locations.length; i++) { if (locations[i][2] =
// == shows all markers of a particular category and ensures the checkbox is checked
function show(category) {
for (var i=0; i<locations.length; i++) {
if (locations[i][2] == category) {
markers[i].setVisible(true);
}
}
}
// hides all markers of a particular category and ensures the checkbox is cleared
function hide(category) {
for (var i=0; i<locations.length; i++) {
if (locations[i][2] == category) {
markers[i].setVisible(false);
}
}
}
// show or hide the categories initially
hide("house");
hide("building");
hide("clothes");
/==显示特定类别的所有标记,并确保选中复选框
功能展示(类别){
对于(var i=0;i使用对象参数
function show() {
for(var j = 0; j<arguments.length; j++){
for (var i=0; i<locations.length; i++) {
if (locations[i][2] == arguments[j]) {
markers[i].setVisible(true);
}
}
}
}
// hides all markers of a particular category and ensures the checkbox is cleared
function hide() {
for(var j = 0; j<arguments.length; j++){
for (var i=0; i<locations.length; i++) {
if (locations[i][2] == arguments[j]) {
markers[i].setVisible(false);
}
}
}
// show or hide the categories initially
hide("house", "building", "clothes");
函数显示(){
对于(var j=0;j您可以使用javascript对象:
toggleShowHide({"house":true,"building":false,"clothes":true});
function toggleShowHide(options) {
for(key in options)
{
if (options.hasOwnProperty(key)) {
for (var i=0; i<locations.length; i++) {
if (locations[i][2] == key) {
markers[i].setVisible(options[key]);
}
}
}
}
toggleShowHide({“house”:true,“building”:false,“cloth”:true});
功能切换显示隐藏(选项){
用于(输入选项)
{
if(options.hasOwnProperty(键)){
对于(VARI=0;我非常感谢!)