Javascript,如何向函数发送占位符变量

Javascript, How to send a placeholder variable to a function?

本文关键字:占位符 变量 函数 Javascript      更新时间:2023-09-26

我有一个if语句的函数。当这个if语句被触发时,我想告诉另一个函数清除它的数组。

function firstFunction(){
    if(!$myCheckBox.is(':checked')){
        secondFunction(myArray.length = 0);
    }
}
function secondFunction(myArray){
    if(myArray.length == 0){
        //Do something
    }
}

renderResult函数期望占位符变量。你应该这样发送:

$('#randomName').change(function() {
if(!$randomName.is(':checked')){
            // modify [results] if needed, e.g. results.length = 0;
            renderResults(results);