如何通过html链接标记传递javascript变量?
问题描述:
<a href="javascript:size('x')">HTML Link</a>
我的html文件中有上述代码,想要将变量x传递给我javascript函数'size()'。
I have the above code in my html file and want to pass on the variable 'x' to my javascript function 'size()'.
在我的javascript文件中,我正在尝试使用如下变量:
In my javascript file, I'm trying to use the variable as follows:
function size(id)
{
document.write("hi user number" + id);
}
我认为我的javascript部分是正确的,我的html语法用于发送变量是错误的,但在谷歌搜索正确的语法有点困难。有人可以帮我吗? thnx!
I think my javascript part is correct and that my html syntax for sending the variable is wrong but having a bit of difficulty googling the correct syntax. Could someone help me here? thnx!
答
我认为你需要返回false。尝试重写链接:
I think you need a return false in there. Try rewriting the link as:
<a href="#" onclick="size( 'x' ); return false;">HTML Link</a>