Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 为锚定标记指定变量值以创建超链接_Javascript_Html - Fatal编程技术网

Javascript 为锚定标记指定变量值以创建超链接

Javascript 为锚定标记指定变量值以创建超链接,javascript,html,Javascript,Html,我想在锚定标记中指定变量a的值以创建超链接 <html> <head> <script> var a="www.google.com"; </script> </head> <body> <a href = "i want the value of a here" / > </body> </html> var a=“www.google.c

我想在锚定标记中指定变量
a
的值以创建超链接

<html>
<head> 
  <script> 
    var a="www.google.com";    
  </script>
</head>
<body>
    <a href = "i want the value of a  here" / > 
</body> 
</html> 

var a=“www.google.com”;

您应该向元素添加一个ID,并通过如下操作修改属性:

const el = document.getelementbyid("thehtmlid")
el.attribute("href", myvalue)

函数可能不是这样命名的,但它应该足够近,可以帮助您创建空的锚标记,然后使用javasript更新href值


让a=”https://www.google.com";
document.getElementById('link')。href=a;

这完全不清楚,请您添加更多说明