< form target =" ...">的不被废弃的等价物 [英] Non-deprecated equivalent of <form target="...">

查看:146
本文介绍了< form target =" ...">的不被废弃的等价物的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要实现一样...

I want to achieve the same as...

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

但是我想发送HTTP POST请求而不是HTTP GET请求。因此,我使用以下内容:

But I want to send a HTTP POST request instead of a HTTP GET request. Thus, I'm using the following:

$('<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 属性已弃用。有没有办法通过非弃用的方法来实现我想做的事情?

However, the target attribute is deprecated. Is there any way to achieve what I'm trying to do by non-deprecated means?

推荐答案


  1. target 只在严格的doctypes中丢失。它不被废弃。最简单的解决方案是使用一个过渡的doctype。

  2. 即使您使用严格的doctype,我所知道的所有浏览器都会做正确的事情。

  3. 如果您必须使用严格的doctype,并且您很关心验证,那么您可以扩展doctype定义:

  1. target is only missing in strict doctypes. It is not deprecated. The simplest solution is to use a transitional doctype.
  2. All browsers that I am aware of do the right thing, even if you use a strict doctype.
  3. If you must use a strict doctype, and you care that much about validation, then you can extend the doctype definition:

只需关于每个浏览器,请注意这个错误。解决方案是将您的XHTML作为 application / xhtml + xml 提供服务,但这将导致IE炸毁,因此您需要在确定内容类型之前嗅探该浏览器。它基本上是一个巨大的黑客在验证表单上的一个小复选框。通常只需使用一个过渡式的doctype就可以简单得多。

Just be aware of this 'bug' in just about every browser. The solution is to serve your XHTML as application/xhtml+xml, but this will cause IE to blow up, so you need to sniff for that browser before determining the content type. It's essentially one giant hack for a tiny check box on a validation form. It's usually a lot simpler to just use a transitional doctype.

<!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> ]>

这篇关于&lt; form target =&quot; ...&quot;&gt;的不被废弃的等价物的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆