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属性已弃用.有没有办法通过非弃用手段实现我想要做的事情?
使用target- 它不被弃用.
target在严格的doctypes中只缺少.它不会被弃用.最简单的解决方案是使用过渡文档类型.几乎每个浏览器都要注意这个"错误".解决方案是为您的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)