社区新版论坛已上线,点击立即前往!使用 openKylin 账户授权登录,解锁更多体验!

openKylin论坛

 找回密码

html调用js变量和函数的几个方法(转载) [复制链接]

  1. <SPAN style="FONT-SIZE: 18px"><html xmlns="http://www.w3.org/1999/xhtml">
  2. <head runat="server">
  3. <title></title>
  4. <script type="text/javascript">
  5. var RestID = 2;//javascript变量
  6. function a() {//javascript函数

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

  9. </script>
  10. </head>

  11. <body>
  12. <form id="form1" runat="server">
  13. <script language="javascript" type="text/javascript">
  14. var str1,str2
  15. str1="fdsgdg dsfdsf china"
  16. str2="武汉市广播电视大学"
  17. document.write("显示字符串1:"+str1+"
  18. ")
  19. document.write("显示字符串2:" + str2 + "
  20. ")

  21. //document.write()函数的写法很重要,写好才能正确的读到javascript的参数
  22. <SPAN style="COLOR: #ff6666">//方式一,打开新窗口,转到新链接

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

  25. <SPAN style="COLOR: #ff9966">//方式二,使用javascript:location.href,但是不能在新窗口中打开链接
  26. </SPAN> <a href= "javascript:location.href= 'showNews.aspx?id= ' + RestID " style=" text-decoration:none; color:Black;" target="_blank"> 目标页 </a>

  27. <SPAN style="COLOR: #33cc00">//方式三,使用javascript:open,只能在搜狗浏览器里打开,在IE、火狐、360浏览器里面都打不开,就是说明这个方法不太好

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

  29. <SPAN style="COLOR: #ff6666">//方式四使用window.open但是鼠标为箭头而不是表示链接时的手型,

  30. </SPAN> <a onclick= "window.open( 'showNews.aspx?id= ' + RestID)" style=" text-decoration:none; color:Black;" target="_blank"> 目标页 </a>
  31. <SPAN style="COLOR: #009900">//方式五调用 javascript函数 ,但是鼠标为箭头而不是表示链接时的手型,
  32. </SPAN>
  33. <a onclick= "javascript:a()" style=" text-decoration:none; color:Black;" target="_blank"> 目标页 </a></form>

  34. </body>
  35. </SPAN>
复制代码
楼主
发表于 2013-7-17 21:45:10
回复

使用道具 举报

openKylin

GMT+8, 2024-7-3 08:39 , Processed in 0.016288 second(s), 18 queries , Gzip On.

Copyright ©2022 openKylin. All Rights Reserved .

ICP No. 15002470-12 Tianjin

快速回复 返回顶部 返回列表