html調用js變量和函數的幾個方法


引自http://blog.csdn.net/shenshen123jun/article/details/18078291

<span style="font-size:18px;"><html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
  <script type="text/javascript"> 
var RestID = 2;//javascript變量
function a() {//javascript函數

    window.open("showNews.aspx?id= " + RestID);
}

</script> 
</head>

<body>
    <form id="form1" runat="server">
    <script language="javascript" type="text/javascript">
    var str1,str2
    str1="fdsgdg dsfdsf china"
    str2="武漢市廣播電視大學"
    document.write("顯示字符串1:"+str1+"<br>")
    document.write("顯示字符串2:" + str2 + "<br>")

  //document.write()函數的寫法很重要,寫好才能正確的讀到javascript的參數
<span style="color:#ff6666;">//方式一,打開新窗口,轉到新鏈接

</span>    document.write(" <a   href= 'showNews.aspx?id="+RestID+"' style='text-decoration:none; color:Black;' target='_blank'> 目標頁 </a> ")
   </script>

<span style="color:#ff9966;">//方式二,使用javascript:location.href,但是不能在新窗口中打開鏈接
</span>    <a   href= "javascript:location.href= 'showNews.aspx?id= ' + RestID " style=" text-decoration:none; color:Black;"  target="_blank"> 目標頁 </a>

<span style="color:#33cc00;">//方式三,使用javascript:open,只能在搜狗瀏覽器里打開,在IE、火狐、360瀏覽器里面都打不開,就是說明這個方法不太好

</span>    <a   href= "javascript:open( 'showNews.aspx?id= ' + RestID)" style=" text-decoration:none; color:Black;"  target="_blank"> 目標頁 </a>

<span style="color:#ff6666;">//方式四使用window.open但是鼠標為箭頭而不是表示鏈接時的手型,

</span>    <a  onclick= "window.open( 'showNews.aspx?id= ' + RestID)" style=" text-decoration:none; color:Black;"  target="_blank"> 目標頁 </a>
<span style="color:#009900;">//方式五調用 javascript函數   ,但是鼠標為箭頭而不是表示鏈接時的手型,
</span>
<a  onclick= "javascript:a()" style=" text-decoration:none; color:Black;"  target="_blank"> 目標頁 </a></form>

</body>
</span>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM