[英]Pass an array to javascript function on anchor tag onclick
I am using an anchor tag for showing dynamic links.I am using javascript function to be called 我正在使用锚标记来显示动态链接。我正在使用javascript函数来调用
on anchor onclick.This is working fine.But the issue is that i want to send an array of values to that javascript function.How can i do that? 在锚点onclick上。这很好用,但是问题是我想向该javascript函数发送值数组。我该怎么做? My anchor tag is defined below,
我的锚标签定义如下,
<a onclick="getbatchreport();" id="anch<?php echo "B-" . trim($value['BATCH_NO']); ?>"><?php echo "B-" . trim($value['BATCH_NO']); ?></a>
<?php //stuff and things ?>
<a href='#' onClick='functionName(<?php echo json_encode($arr); ?>)'>Click Me</a>
<script type='text/javascript'>
function functionName(arr){
arr = JSON.parse(arr);
alert(arr[0]);
alert(arr[1]);
alert(arr[2]);
}
</script>
EDIT: Fixed after the author indicated PHP was also involved. 编辑:在作者指出PHP也参与其中后修复。 Also note that JavaScript handles Associative Arrays weirdly.
另请注意,JavaScript怪异地处理了关联数组。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.