变量javascript无法正常工作

时间:2016-06-18 23:47:58

标签: javascript

When using buka_halaman('produk','1') then working but when using variable is not working



function rute(){
//window.onhashchange = function(){
  switch(location.hash) {
    case location.hash:
	var abc = location.hash.split('#')[1]; // ex: domain.com/page.html#produk','1
	var def = "'"+abc+"'";
	if (abc!=undefined){
      alert(def);
      buka_halaman(def); //error
	  buka_halaman('produk','1') //working
	  }
    break;
  }
//}
}




1 个答案:

答案 0 :(得分:1)

改变这个:

var def = "'" + abc + "'";

到此:

var def = abc;

除非您不需要def变量,否则您可以直接使用abc

buka_halaman(abc, '1');

您的代码将单引号字符放入字符串中。