close
我瘋了.....><
1. 傳統法: 簡單實用 清楚明瞭 我本來的寫法
<a href="show.php">GO<a>
2. 用PHP+Smarty: 抄我們家其它網頁來的方法 必須把整頁回傳給PHP Server
會這樣用是因為某次會議說這個link一定得寫成button
完全不知道好處在哪...
好啦 承認一下 如果有東西要回傳PHP server
而下個頁面的顯示又跟這些東西有關的時候 得用這個方法
上半部是php那邊的敘述, 下半部是template
( 這個用法中間有很多設定都是其他高手已經寫好了
所以這段程式碼是不能獨立執行的 )
<?php
if( isset($action) && $action=="changeURL" )
header("location:show.php");
?>
-------------------
<script language="JavaScript">
function changeURL() {
document.getElementById('form1').action.value="changeURL";
document.getElementById('form1').submit();
}
</script>
<form id="form1" name="form1">
<input type="hidden" name="action" value="">
<input type="button" value="GO" onClick="changeURL()">
</form>
if( isset($action) && $action=="changeURL" )
header("location:show.php");
?>
-------------------
<script language="JavaScript">
function changeURL() {
document.getElementById('form1').action.value="changeURL";
document.getElementById('form1').submit();
}
</script>
<form id="form1" name="form1">
<input type="hidden" name="action" value="">
<input type="button" value="GO" onClick="changeURL()">
</form>
3. 用JavaScript function: 這是我最後用的方法 翻書找了很久才抄到的
不失為一個好用的方 (如果死都不能接受傳統文字型的link的話)
<script language="JavaScript">
function changeURL(strurl)
window.location.href = strurl;
</script>
<input type="button" value="GO" onClick="changeURL('show.php')">
function changeURL(strurl)
window.location.href = strurl;
</script>
<input type="button" value="GO" onClick="changeURL('show.php')">
4. 用JavaScript: 其實我已經把三種方法都寫好 也貼出去了 才想到可以這樣寫
不如function有彈性 不過比function更簡潔
<input type="button" value="GO" onClick="window.location.href='show.php';">
(分號可寫可不寫啦 不過因為單引號跟雙引號放在一起很難辨認 所以我加了)
最近越來越喜歡少打幾個字的方法 orz
結論: 好好的一個link不用 幹麻一定要用button呢? 又不會比較好看 ><
全站熱搜