如何转换onchange ="this.form.submit()"?到jQuery [英] How to convert onchange="this.form.submit()" to jquery

查看:117
本文介绍了如何转换onchange ="this.form.submit()"?到jQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将onchange="this.form.submit()"转换为jQuery格式?

How to convert the onchange="this.form.submit()" to jQuery format?

<form action="process.php" method="post">
  <select name="qty" onchange="this.form.submit()">
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    <option value="4">4</option>
  </select>
</form>

我遇到了问题,因为如果使用onchange="this.form.submit()"

I got a problem because some of browser will do nothing on the process.php if use onchange="this.form.submit()"

让我知道..

推荐答案

您无需执行任何操作.尽管您可以将this.form.submit()更改为$(this).closest('form').submit(),但这不会产生任何影响(除了可读性较差之外),因为所有jQuery都会通过调用this.form.submit()来实现.

You don't need to do anything. Whilst you can change this.form.submit() to $(this).closest('form').submit(), this will have no effect (apart from being slightly less readable) as all jQuery will do with that will be to call this.form.submit().

如果您在使用纯JavaScript提交表单时遇到问题,则在使用jQuery提交表单时仍然会遇到同样的问题.到底是什么问题?

If you have a problem with submitting the form from plain JavaScript, you will still have the same problem submitting it with jQuery. What exactly is that problem?

在任何情况下,通常都不应使用自动提交选择框.它们破坏了键盘的可访问性(因为IE在使用键盘后会过早触发onchange),并且与后退按钮的交互性很差.

In any case you should generally not use auto-submitting select boxes. They break keyboard accessibility (since IE fires onchange prematurely from keyboard use) and they interact poorly with the back button.

这篇关于如何转换onchange ="this.form.submit()"?到jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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