html调用js变量和函数的几个方法

来源:互联网 发布:ubuntu 触摸板手势 编辑:程序博客网 时间:2024/05/28 19:25
<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的参数//方式一,打开新窗口,转到新链接    document.write(" <a   href= 'showNews.aspx?id="+RestID+"' style='text-decoration:none; color:Black;' target='_blank'> 目标页 </a> ")   </script>//方式二,使用javascript:location.href,但是不能在新窗口中打开链接    <a   href= "javascript:location.href= 'showNews.aspx?id= ' + RestID " style=" text-decoration:none; color:Black;"  target="_blank"> 目标页 </a>//方式三,使用javascript:open,只能在搜狗浏览器里打开,在IE、火狐、360浏览器里面都打不开,就是说明这个方法不太好    <a   href= "javascript:open( 'showNews.aspx?id= ' + RestID)" style=" text-decoration:none; color:Black;"  target="_blank"> 目标页 </a>//方式四使用window.open但是鼠标为箭头而不是表示链接时的手型,    <a  onclick= "window.open( 'showNews.aspx?id= ' + RestID)" style=" text-decoration:none; color:Black;"  target="_blank"> 目标页 </a>//方式五调用 javascript函数   ,但是鼠标为箭头而不是表示链接时的手型,<a  onclick= "javascript:a()" style=" text-decoration:none; color:Black;"  target="_blank"> 目标页 </a></form></body>


原创粉丝点击