如何给按钮加上链接功能

<div id="veryContent" class="real_blog" style="text-indent: 2em; height: auto !important;">
<table id="blogContentTable" style="width: 100%;" border="0" cellspacing="0" cellpadding="0"><tbody><tr>
<td style="" valign="top">
<div id="blogContainer" style="height: 100%; overflow: hidden;">
<img id="paperPicArea0" style="display: none;" src="http://writeblog.csdn.net/ac/b.gif" alt=""><div id="paperTitleArea"></div>
<img id="paperPicArea" style="display: none;" src="http://writeblog.csdn.net/ac/b.gif" alt=""><div id="blogDetailDiv" style="font-size: 16px;">脚本说明: <br>把如下代码加入<body>区域中 <br><INPUT TYPE="submit" value="建站资源网" οnclick="location.href='http://www.jzzy.com'"> <br><br><br>按钮链接乾坤大挪移 <br>作为一个小技巧,暂时归类到ASP中。 <br>在设计网站的时,我们可能会想把链接做成按钮的样子,按钮做成链接的样子。下面说一下我的方法。 <br>1、按钮做成链接(图片)的样子 <br>提交按钮<input type="submit" value="提交"> <br>提交链接<a href="#" οnclick="表单名字.submit()">提交</a> <br>重置按钮<input type="reset" value="重置"> <br>重置链接<a href="#" οnclick="表单名字.reset()">重置</a> <br>普通按钮<input type="button" value="按钮" οnclick="函数()"> <br>普通链接<a href="#" οnclick="函数()">链接</a> <br>至于图片也一样把a标签换成img <br>2、链接做成按钮的样子 <br><a href="reg.asp">注册</a> <br>=><input type="button" value="注册" οnclick="location.href='reg.asp'"> <br>----------------------------------- <br>有的时候我们完全可以手工做一个get方式的表单,至于用按钮还是链接随心所欲。 <br><form action="xx.asp" method="get" name="form1"> <br><input name="aa" type="text" id="aa"> <br><input name="bb" type="text" id="bb"> <br><input type="submit" name="Submit" value="提交"> <br></form> <br>=> <br><input name="aa" type="text" id="aa"> <br><input name="bb" type="text" id="bb"> <br><input type="button" value="按钮" οnclick="location.href='xx.asp?aa='+document.all['aa'].value+'&bb='+document.all['bb'].value"> <br>----------------------------------- <br>进一步说我们还可以做一个按钮(链接)来同时传递js变量,表单input的值,asp变量,Recordset值 <br><script language="javascript"> <br>var id1=1; <br></script> <br><% <br>id3=3 <br>.... <br>rs.open exec,conn,1,1 <br>假设有rs("id4")=4 <br>... <br>%> <br><input name="id2" type="text" id="id2" value="2"> <br><input type="button" value="按钮" <br>οnclick="location.href='xx.asp?id1='+id1+'&id2='+document.all['id2'].value+'&id3=<%=id3%>&id4=<%=rs("id4")%>'"> <br>我们按下按钮会看到浏览器的url是xx.asp?id1=1&id2=2&id3=3&id4=4 <br>在xx.asp中我们就可以用request.querystring来得到所有变量,这样是不是变相的客户端js和服务器段的变量传递? <br>------------------------------------------------------------------------------------------------------------------------------ <br>如何给按钮加上链接功能 <br><br><br>解决思路: <br>按钮属于控件级的对象,优先级比较高,所以不能象图片或文本一样直接加链接,只能通过按钮的单击事件调用脚本的方式来实现。 <br>具体步骤: <br>1.在原窗口打开链接 <br><input type="button" value="闪吧" onClick="location=’http://www.flash8.net’"> <br><button onClick="location.href=’http://www.flash8.net’">闪吧</button> <br><form action="http://www.flash8.net"><input type="submit" value="打开链接"></form> <br>2.在新窗口中打开链接 <br><input type="button" <br>value="闪吧" onClick="window.open(’http://www.flash8.net’)"> <br><button onClick="window.open(’http://www.flash8.net’)">闪吧</button> <br><form action="http://www.flash8.net" <br>target="_blank"><input type="submit" value="打开链接"></form> <br>注意:onClick调用的代码里的引号在只有一重时可以单双嵌套,超过两重就必须用"/"号转义且转义的引号必须跟里层的引号一致,如: <br><button onClick="this.innerHTML=’<font color=/’red/’>http://www.flash8.net</font>’">闪吧</button> <br>或 <br><button onClick=’this.innerHTML="<font color=/"red/">http://www.flash8.net</font>"’>闪吧</button> <br>而下面都是错误的写法: <br><button onClick="this.innerHTML=’<font color=’red’>http://www.flash8.net</font>’">闪吧</button> <br><button onClick="this.innerHTML=’<font color="red">http://www.flash8.net</font>’">闪吧</button> <br><button onClick="this.innerHTML=’<font color=/"red/">http://www.flash8.net</font>’">闪吧</button> <br>提示:大部分属于window或document对象的方法和属性都可以省略前缀window或document,比如说本例中的location.href(location.href又可以简写为location,因为location的默认对象为href)就是window.location.href或document.location.href的省略式写法。 <br>技巧:本例中还可以用下面的方法来代替location.href <br>location.replace(url) <br>location.assign(url) <br>navigate(url) <br>特别提示 <br>第一步中的代码运行后,单击按钮将跳转到链接目标。而第二步的在单击按钮后将在新窗口中打开链接。 <br>特别说明 <br><br>本例主要是通过用onClick捕获用户在按钮上的单击事件,然后调用location对象的href方法或window对象的open方法来打开链接。另外一个技巧是通过提交表单来实现链接功能,按钮必须是type=submit类型的按钮,表单的action值就是链接目标,target值就是链接打开的目标方式。 <!--v:3.2-->
</div>
</div>
</td>
</tr></tbody></table>
</div>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值