如何使用API​​数据创建链接?

时间:2019-04-15 05:37:39

标签: javascript html api

如何创建包含来自API参考的数据的href链接?

示例:下面我的代码中的href链接应如下所示:http://playrust.io/map/?Procedural%20Map_4000_383652508

<!DOCTYPE HTML>
<html>
	<head>
    		<script> players_cur1 = players_cur; players_max1 = players_max; entities1 = entities; is_online1 = is_online; map_size1 = map_size; map_seed1 = map_seed; fps1 = fps; </script>
		    <script src="https://api.rust-servers.info/embed.js?id=3"></script>
		    <script> players_cur2 = players_cur; players_max2 = players_max; entities2 = entities; is_online1 = is_online; map_size2 = map_size; map_seed2 = map_seed; fps2 = fps; </script>
  </head>
  
  <a target="_blank" href="http://playrust.io/map/?Procedural%20Map_<script>document.write(map_size1);</script>_<script>document.write(map_seed1);</script>">Map</a>
</html>

1 个答案:

答案 0 :(得分:1)

只需将其写入页面:

document.write(`<a target="_blank" href="http://playrust.io/map/?Procedural%20Map_${map_size1}_${map_seed1}>Map</a>`);