How do I pass on javascript variables through a ht

2019-08-22 01:06发布

<a href="javascript:size('x')">HTML Link</a>

I have the above code in my html file and want to pass on the variable 'x' to my javascript function 'size()'.

In my javascript file, I'm trying to use the variable as follows:

function size(id) 
{
   document.write("hi user number" + id);
}

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!

2条回答
Fickle 薄情
3楼-- · 2019-08-22 01:30

I think you need a return false in there. Try rewriting the link as:

<a href="#" onclick="size( 'x' ); return false;">HTML Link</a>
查看更多
登录 后发表回答