[英]What is the format for creating an href link using a variable?
我希望我的href鏈接基於可能會更改但始終使用相同頁面名稱about.html的域名。
下面的javascript代碼標識該域應為abc.com還是xyz.com。 我的問題是我不知道如何編寫HTML代碼,以使href等於:abc或xyz的引用鏈接以及about.html。
Java腳本
$(".abcORxyz").html(document.referrer);
HTML
<a href="What do I need to put here? + .about.html">Other About Page</a>
您根本不需要在href
屬性中放置任何內容。 您似乎正在使用jQuery,因此可以使用jQuery在頁面加載時設置href
屬性。
jQuery的
$(document).ready(function() {
$("#aboutLink").attr("href",document.referrer + ".about.html");
});
HTML
<a id="aboutLink" href="#">Other About Page</a>
作為附帶說明,我鼓勵您不要為此目的使用document.referrer
,因為您永遠不知道該引用者實際上是什么。 如果Google是讓訪問者進入您正在使用此頁面的頁面,該怎么辦? 該鏈接最終看起來像https://www.google.com/search?q=about&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a.about.html
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.