Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Onclick将变量调用到数据中_Javascript_Variables_Onclick - Fatal编程技术网

Javascript Onclick将变量调用到数据中

Javascript Onclick将变量调用到数据中,javascript,variables,onclick,Javascript,Variables,Onclick,我已经在head中将“branch”声明为一个变量。它是一个JavaScript函数,用于提取url字符串的一部分,然后该函数将其声明为“分支”。i、 e pieshop.co.uk/bristol/buy “分行”=布里斯托尔 上面的工作很好 当用户单击某个按钮时,我希望它发送一些固定数字和变量“branch”,这些数字和短语“branch”都正确发送,但不会更改为我声明的变量 我现在已经把这些放在一起了 <a href='http://www.google.com' onClick='

我已经在head中将“branch”声明为一个变量。它是一个JavaScript函数,用于提取url字符串的一部分,然后该函数将其声明为“分支”。i、 e

pieshop.co.uk/bristol/buy

“分行”=布里斯托尔

上面的工作很好

当用户单击某个按钮时,我希望它发送一些固定数字和变量“branch”,这些数字和短语“branch”都正确发送,但不会更改为我声明的变量

我现在已经把这些放在一起了

<a href='http://www.google.com' onClick='function("1256", "468", "branch" );' target="_blank">send data</a>


如何让它拉入“branch变量?”

“branch”
是一个字符串文本,您不能给它赋值。如果你想让它成为变量名,就把引号去掉。

假设你有这样的东西

<script type="text/javascript">
  var branch = 'bristol';
  function myFunc(a, b, c){
    // do sth. with abc
    alert(c);
  }
</script>

var分支=‘布里斯托尔’;
函数myFunc(a,b,c){
//用abc做某事
警报(c);
}
你可以:

<a href='http://www.google.com' onClick='myFunc("1256", "468", branch );' target="_blank">send data</a>