如何组合这两个JavaScript函数? var curtext=“查看大图像”; 函数changeSrc(){ 如果(curtext==“查看大图像”){ document.getElementById(“boldStuff”).innerHTML=“查看小图像”; curtext=“查看小图像”; }否则{ document.getElementById(“boldStuff”).innerHTML=“查看大图像”; curtext=“查看大图像”; } } var curimage=“小屋”\u small.jpg”; 函数changeSrc(){ if(curimage==“小屋”\u small.jpg){ document.getElementById(“myImage”).src=“fatch_large.jpg”; curimage=“村舍_large.jpg”; }否则{ document.getElementById(“myImage”).src=“小屋”\u small.jpg”; curimage=“村舍小.jpg”; } } 粉红小丘酒店 独栋住宅

如何组合这两个JavaScript函数? var curtext=“查看大图像”; 函数changeSrc(){ 如果(curtext==“查看大图像”){ document.getElementById(“boldStuff”).innerHTML=“查看小图像”; curtext=“查看小图像”; }否则{ document.getElementById(“boldStuff”).innerHTML=“查看大图像”; curtext=“查看大图像”; } } var curimage=“小屋”\u small.jpg”; 函数changeSrc(){ if(curimage==“小屋”\u small.jpg){ document.getElementById(“myImage”).src=“fatch_large.jpg”; curimage=“村舍_large.jpg”; }否则{ document.getElementById(“myImage”).src=“小屋”\u small.jpg”; curimage=“村舍小.jpg”; } } 粉红小丘酒店 独栋住宅,javascript,function,arguments,Javascript,Function,Arguments,小屋:149000美元 两张床,一个浴室,1189平方英尺,1.11英亩 我需要帮助,如何把两个参数作为一个函数?这意味着当您单击时,图像和文本都将更改。 非常感谢。 Bianca创建一个新函数,同时调用它们,并将它们重命名为独特的名称 function combined(curtext, curimage){ if(curtext == "View large image"){ document.getElementById("boldStuff").innerHTML

小屋:149000美元 两张床,一个浴室,1189平方英尺,1.11英亩

我需要帮助,如何把两个参数作为一个函数?这意味着当您单击时,图像和文本都将更改。 非常感谢。
Bianca

创建一个新函数,同时调用它们,并将它们重命名为独特的名称

function combined(curtext, curimage){
  if(curtext == "View large image"){
      document.getElementById("boldStuff").innerHTML = "View small image";
        curtext="View small image"; 
      }
      else{
       document.getElementById("boldStuff").innerHTML= "View small image";
           curtext="View large image";    
  }
  if(curimage == "cottage_small.jpg"){
       document.getElementById("myImage").src="cottage_large.jpg";
       curimage="cottage_large.jpg";
        }
      else{
       document.getElementById("myImage").src="cottage_large.jpg";    
       curimage="cottage_small.jpg";
  }
}

这也消除了您对globals的依赖。

Ahhh,很抱歉我尽力编辑了这个问题。该下班了。
function combined(curtext, curimage){
  if(curtext == "View large image"){
      document.getElementById("boldStuff").innerHTML = "View small image";
        curtext="View small image"; 
      }
      else{
       document.getElementById("boldStuff").innerHTML= "View small image";
           curtext="View large image";    
  }
  if(curimage == "cottage_small.jpg"){
       document.getElementById("myImage").src="cottage_large.jpg";
       curimage="cottage_large.jpg";
        }
      else{
       document.getElementById("myImage").src="cottage_large.jpg";    
       curimage="cottage_small.jpg";
  }
}
var changeCombined = function() {
    changeTxt();
    changeSrc();
};

function changeTxt() {
    var node = document.getElementById("boldStuff");

    if ( node.innerHTML == "View large image") {
        node.innerHTML = "View small image";
    } else {
        node.innerHTML = "View large image";
    }
}

function changeSrc() {
    var image = document.getElementById("myImage");

    if ( image.src == "cottage_small.jpg") { 
        image.src = "cottage_large.jpg";
    } else {
        image.src = "cottage_small.jpg";
    }
}