Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/407.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 通过<;将参数传递到url;a>;标记int-html_Javascript_Html - Fatal编程技术网

Javascript 通过<;将参数传递到url;a>;标记int-html

Javascript 通过<;将参数传递到url;a>;标记int-html,javascript,html,Javascript,Html,我在变量(var lan=urlParam('language'))中有所选语言。 我想在“a”标记中的url中将此语言作为参数传递(不使用PHP),如下所示: <a href="http://hotelscombined.sitewish.gr/HotelNameSearch.aspx?languageCode=lan"> 但它不起作用 我在等你的回答。 非常感谢。如果我理解正确,您可以使用document.write打印链接并添加变量作为语言参数 <script t

我在变量(
var lan=urlParam('language')
)中有所选语言。 我想在“
a
”标记中的url中将此语言作为参数传递(不使用PHP),如下所示:

<a href="http://hotelscombined.sitewish.gr/HotelNameSearch.aspx?languageCode=lan"> 

但它不起作用

我在等你的回答。
非常感谢。

如果我理解正确,您可以使用document.write打印链接并添加变量作为语言参数

<script type="text/javascript">document.write("<a href=\"http://hotelscombined.sitewish.gr/HotelNameSearch.aspx?languageCode=" + lan + "\">link description</a>");</script>
document.write(“”);

您的url位于一个字符串中,因此它不会放入变量的值,而只放入字符串“lan”

给你的链接一个ID,这样你就可以用javascript修改它的url

<a id="foo" href="http://hotelscombined.sitewish.gr/HotelNameSearch.aspx">

您希望使用JavaScript动态地向页面上的每个链接添加一个新的GET参数。对吗?
document.getElementById('foo').setAttribute('href', 'http://hotelscombined.sitewish.gr/HotelNameSearch.aspx?languageCode=' + lan);