我是一個使用XHTML模板創建電子商務網站的新手。我想在某些項目下添加免責聲明,但不是全部。爲避免在每個條目下鍵入免責聲明(並且如果免責聲明發生變化,將來避免出現問題),我希望使用javascript創建一個副本塊,當我指向它時,會添加免責聲明。我已經成功完成了(yah!),但是在免責聲明中是指向pdf的鏈接。當我使用html鏈接到PDF時,它失敗。我知道這可能是因爲我沒有正確的語法,因爲HTML是JavaScript代碼中的「內部」。有人可以幫忙嗎?如何在JavaScript中創建指向PDF的鏈接?
這是我有:
//<![CDATA[
function openPDF(file)
{
window.open (file, 'resizable,scrollbars');
}
//]]>
</script>
<script type="text/javascript">
//<![CDATA[
onload=function()
{
var txt=document.getElementById("myDiv")
txt.innerHTML="Photos do not represent actual size. Refer to measurements for sizing.
Measurements are approximate. Colors shown may differ depending on your computer
settings. Colors described are subjective and colors may vary from piece to piece,
depending on the natural properties of the stones. To learn more, see our <a href="#"
onClick="openPDF('www.shop.site.com/media/JewelryGuide.pdf')">Jewelry Guide</a>.";
}
//]]>
</script>
下面是我用它調用的代碼:
<div id="myDiv"></div>`