将Javascript变量传递给HTML href?

时间:2015-10-13 02:14:40

标签: javascript php jquery html html5

我有以下代码,并希望将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的值

1 个答案:

答案 0 :(得分:2)

为什么不在displaylightbox内拨打jsfunction来呼叫onclick

像这样

function jsfunction() {
    var var_x = 10;
    displaylightbox('./page1.php?name=' + var_x, {});
};