设置变量后运行Javascript函数

设置变量后运行Javascript函数,javascript,function,variables,isset,equivalent,Javascript,Function,Variables,Isset,Equivalent,我有以下职能: // NATION var x, y, z; function flag(nation,area) { x = nation; this.nation=nation; var el=document.getElementById("desc"); el.innerHTML='The region you have selected is <b>'+area+'</b>'; document.getElementById("flag").innerHTML=

我有以下职能:

// NATION
var x, y, z;
function flag(nation,area)
{
x = nation;
this.nation=nation;
var el=document.getElementById("desc");
el.innerHTML='The region you have selected is <b>'+area+'</b>';
document.getElementById("flag").innerHTML='<img src="images/flags/'+nation+'.jpg">';
}
// SERVICE
function output(service)
{
y = service;
this.service=service;
var el=document.getElementById("service-desc");
el.innerHTML='You have selected a <b>'+service+'</b> service.';
document.getElementById("clock").innerHTML='<img src="images/clock-'+service+'.png">';
}
能不能有人被刺伤到让我知道怎么做

谢谢, B


编辑-抱歉,忘了说变量来自onclick(onclick=“flag('scottislands','Scottish islands');”)

我想你是在寻找被触发的某种事件,也许还有一种方法,但在这种情况下,我只需要从每个函数调用一个检查:

function selectmodel()
{
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
  {
  alert ("Your browser does not support XMLHTTP!");
  return;
  }
var location=x;
var time=y;
var weight=z;
var url="selectmodel.php";
url=url+'?location='+location+'&time='+time+'&weight='+weight;
xmlhttp.onreadystatechange=stateChanged1;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
window.location.hash="slider";
}
function stateChanged1()
{
if (xmlhttp.readyState==4)
  {
  document.getElementById("result").innerHTML=xmlhttp.responseText;
  }
}
var x = null;
var y = null;
var ...

function trySelectModel() {
  if (x == null) || (y == null) return;
  selectModel(); // Your function
}

function flag(...) {
  // Your existing code
  trySelectModel();
}

function output(service) {
  // Your existing code
  trySelectModel();
}

function selectmodel() {
  // Your existing code
}

嗨,if(x==null)| |(y==null)是否返回;如果一个或两个变量都为null,则不说run if null?不,它跳出函数,即在这种情况下永远不会调用selectModel行。