1、直接使用input在原有的標簽頁中直接打開一個頁面,將原有標簽頁覆蓋
在按鈕中直接打開一個連接,
這里不需要用到js的代碼,根據HTML中的onclick屬性
<input type
=
"button" name
=
"btnEdit" value
=
"編輯" onclick
=
"window.location.href='<?=base_url()?>index.php/admin/expert/expertEdit/<?=$expertId?>';" id
=
"btnEdit"
class
=
"input"
/
>
2、JS打開超鏈接的幾種形式
- window.open(''url'') 打開一個新的標簽頁
$(
'#gradePaper').click(
function(){
window.open(
'<?=base_url()?>index.php/admin/search/searchAllByCode');
});
- 用自定義函數
<script
>
function openWin(tag,obj)
{
obj.target
=
"_blank";
obj.href
=
"Web/Substation/Substation.aspx?stationno="
+tag;
obj.click();
}
<
/script
>
<a href
=
"javascript:void(0)" onclick
=
"openWin(3,this)"
>超鏈接
<
/a
>
- window.location.href=""; 這種方式也是覆蓋原有的標簽頁的方式打開
3、js和jquery控制超鏈接,使鏈接在子窗口打開
- 這是用jquery,讓其所有超鏈接在新窗口打開
<script type
=
"text/javascript" src
=
"JQuery/jquery-1.4.2.js"
>
<
/script
>
<script type
=
"text/javascript"
>
$(document).ready(
function() {
$(
"a").attr(
"target",
"_blank");
})
<
/script
>
- 用jquery,想讓一部分超鏈接在新窗口打開,只要在基范圍加個id就好了,比如:
<div id
=
"ccc"
>
<a href
=
"index.html"
>首頁
<
/a
>
<
/div
>
<script type
=
"text/javascript" src
=
"JQuery/jquery-1.4.2.js"
>
<
/script
>
<script type
=
"text/javascript"
>
$(document).ready(
function() {
$(
"div#ccc a").attr(
"target",
"_blank");
})
<
/script
>