提交表单以供选择option.onClick [英] Submit Form for select option.onClick

查看:108
本文介绍了提交表单以供选择option.onClick的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户使用jQuery单击选项时,我将如何提交表单?我在使用datepicker文本输入时发现了一个类似的问题,但我对jQuery并不熟悉,因此似乎无法将其转换为适用于选择项.

How would I submit a form when the user clicks an option using jQuery? I found one similar question using the datepicker text input but I'm not that familiar with jQuery so I can't seem to convert it to work for a select item.

推荐答案

<option>click上:

$('option').click(function ()
{
    $(this).closest('form').submit();
});

<select>change上(可能是您想要的那个):

On change of a <select> (this is probably the one you want):

$('select').change(function ()
{
    $(this).closest('form').submit();
});


@Guffa评论:


As @Guffa commented:

选项上的click事件并非在所有浏览器中都有效.例如Safari不会触发它.

The click event on options doesn't work in all browsers. Safari for example does't trigger it.

...所以你绝对想要第二个.

...so you definitely want the second one.

这篇关于提交表单以供选择option.onClick的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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