2011-01-28 56 views
6

我想達到相同...非棄用等效

window.open('lalala.php', 'lalala', '...'); 

但我想發送HTTP POST請求而不是HTTP GET請求。因此,我使用了以下內容:

$('<form/>').attr('action', 'lalala.php') 
      .attr('target', 'lalala')  // w3schools.org says this is deprecated 
      .attr('method', 'post') 
      .append(hiddenParam('param1', param1)) 
      .append(hiddenParam('param2', param2)) 
      .submit().remove(); 

// hiddenParam is a function I created that returns an input tag 
// the type attribute set to hidden, 
// the id attribute set to the first parameter, 
// and the value attribute set to the second parameter 

然而,target屬性已被棄用。有沒有辦法通過非棄用的方式來實現我想要做的事情?

+11

不要總是相信W3Schools的 – 2011-01-28 13:39:36

+6

*不要*相信W3Schools的,直到你已經看到,實際上是值得信賴的來源證據支持。 – Quentin 2011-01-28 13:51:29

+0

那麼,這是一個可靠的來源? (並且,順便說一下,W3C是否可以起訴這些w3schools球員?) – pyon 2011-01-28 13:54:54

回答

5
  1. target只在嚴格的文檔類型中丟失。它不被棄用。最簡單的解決方案是使用過渡文檔類型。
  2. 即使您使用嚴格的文檔類型,我所知道的所有瀏覽器都會做正確的事情。
  3. 如果你必須使用一個嚴格的doctype,你在意驗證這一點,那麼你可以擴展文檔類型定義:

要知道的this 'bug' in just about every browser。解決方案是將您的XHTML作爲application/xhtml+xml,但這會導致IE崩潰,因此您需要在確定內容類型之前嗅探該瀏覽器。對於驗證表單上的一個小複選框,它本質上是一個巨大的黑客攻擊。僅使用過渡型文檔通常要簡單得多。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" [ <!ATTLIST form target CDATA #IMPLIED> ]> 
6

使用target - 它不被棄用。

0

添加

<form target="lalala" ...></form>