不推荐等价于<form target ="...">

pyo*_*yon 6 html forms xhtml dom

我希望实现与...相同

window.open('lalala.php', 'lalala', '...');
Run Code Online (Sandbox Code Playgroud)

但我想发送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
Run Code Online (Sandbox Code Playgroud)

但是,该target属性已弃用.有没有办法通过非弃用手段实现我想要做的事情?

Que*_*tin 6

使用target- 它不被弃用.

  • 他们错了(像往常一样:http://w3fools.com/)我挑战你在http://www.w3.org/TR/html4/index/attributes上的目标属性的Deprecated列中找到一个D. html或任何其他官方规范中的引用. (7认同)
  • @Floern - "不存在"和"弃用"是两回事.它们之间没有1:1的相关性. (2认同)

Mat*_*ley 5

  1. target在严格的doctypes中只缺少.它不会被弃用.最简单的解决方案是使用过渡文档类型.
  2. 即使您使用严格的doctype,我所知道的所有浏览器都会做正确的事情.
  3. 如果您必须使用严格的doctype,并且您非常关心验证,那么您可以扩展doctype定义:

几乎每个浏览器都要注意这个"错误".解决方案是为您的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> ]>
Run Code Online (Sandbox Code Playgroud)

  • `target`在任何地方都不被弃用.它只是没有出现在严格的doctypes中. (3认同)