聽起來像你需要附加到窗體或特定鏈接的東西。如果事件是由鏈接引發的,並且有一個請求字符串充滿變量,則它將充當GET。如果是表單,則必須檢查METHOD,然後根據表單本身提交的數據來確定URL。
<a href="thisPage.php">No method</a>
<a href="thisPage.php?usrName=jonathan">GET method</a>
<form method="GET" action="thisPage.php">
<!-- This is a GET, according to the method -->
<input type="text" name="usrName" value="jonathan" />
</form>
<form method="POST" action="thisPage.php">
<!-- This is a POST, according to the method -->
<input type="text" name="usrName" value="jonathan" />
</form>
因此,檢測不會發生在window方法中,而是發生在您的鏈接的點擊方法和表單提交中。
/* Check method of form */
$("form").submit(function(){
var method = $(this).attr("method");
alert(method);
});
/* Check method of links...UNTESTED */
$("a.checkMethod").click(function(){
var isGet = $(this).attr("href").get(0).indexOf("?");
alert(isGet);
});
是的,我想知道我是如何從檢查的JavaScript方法? 例如這樣的東西..例如window.Method ==「POST」 – rid00z 2009-02-16 23:21:32