我有以下代码,并希望将Javascript变量(var_x)传递给HTML href路径inoder,就像这样javascript:displaylightbox('./page1.php?name=var_x',{})
<a href="javascript:displaylightbox('./page1.php?name=',{})" target="_self" onclick="jsfunction();return false;"><img src="i/i.png" id="Image1" alt="" style="width:75px;height:75px;"></a></div>
<script>
function jsfunction()
{
var var_x = 10;
//some other code
};
</script>
它应该在灯箱窗口中打开并重定向到此page1.php?name = 10,因为10是var_x的值
答案 0 :(得分:2)
为什么不在displaylightbox
内拨打jsfunction
来呼叫onclick
function jsfunction() {
var var_x = 10;
displaylightbox('./page1.php?name=' + var_x, {});
};