使用jQuery提交表单下拉菜单 [英] Submit Form dropdown with jQuery
问题描述
我正在使用一个名为 dropkick 的下拉插件,该插件将选择菜单替换为外观更好的自定义下拉菜单.我想在此下拉列表中显示我的WordPress类别列表.这是生成下拉列表的PHP代码:
I am using a dropdown plugin called dropkick, which replaces select menus with better looking, custom dropdowns. I want to display my list of WordPress categories in this dropdown. Here is the PHP code that generates the dropdown:
<form action="<?php bloginfo('url'); ?>/" method="get" class="pretty">
<?php $select = wp_dropdown_categories('show_option_none=Select category&show_count=1&orderby=name&echo=0');
echo $select; ?>
</form>
将其转换为漂亮的下拉菜单"的JavaScript代码如下.
The JavaScript code to turn this into a "pretty dropdown" is as follows.
$('.pretty select').dropkick({
theme: 'default',
change: function (value, label) {
INSERT CALLBACK HERE
}
});
我需要编写一个回调,该回调将在用户选择类别后提交表单.我该怎么办?
I need to write a callback that will submit the form after the user selects a category. How would I go about this?
我尝试使用return this.form.submit()
和return $(this).parent().form.submit()
,但是没有提交表格.如何使用jQuery自动提交表单?
I tried using return this.form.submit()
and also return $(this).parent().form.submit()
but that did not submit the form. How can I auto submit a form using jQuery?
表单动作和方法已经在表单中定义.
The form action and method are already defined in the form.
推荐答案
您可以使用jQuery的 .submit()
发布表单.
You can use jQuery's .submit()
to post the form.
鉴于您在DOM中只有一个具有pretty
类的表单,您可以像这样发布表单:
Given that you only have one form in the DOM with the class pretty
, you could post the form like this:
$("form.pretty").submit();
这篇关于使用jQuery提交表单下拉菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!