简体   繁体   English

如何选择一个收音机然后在 vBulletin 中使用 jQuery 提交表单?

[英]How to select a radio then submit form with jQuery in vBulletin?

I am working on a userscript that injects my own JS into the head (this part works).我正在开发一个用户脚本,将我自己的 JS 注入头部(这部分有效)。 I am utilizing the site's already in-place jQuery.我正在使用该站点已经就位的 jQuery。

I am a moderator on a vBulletin forum.我是 vBulletin 论坛的版主。 I move and close A LOT of threads.我移动并关闭了很多线程。 I figured it would save me insurmountable amount of time if I reduced the total number of clicks I make by 2 clicks per thread.我认为如果我将每个线程的总点击次数减少 2 次,这将为我节省无法逾越的时间。

Using .append() I've added my own <td> with a "quick access" <a> tag.使用.append()我添加了我自己的带有“快速访问” <a>标签的<td>
What I would like to happen is for when I click the <a> tag (Close or Move) it selects the appropriate option in the thread tools form (which as far as I can tell is working the way I have it coded) and then submit the form as if I had hit the Perform Actions button.我想要发生的是当我单击<a>标签(关闭或移动)时,它会在螺纹工具表单中选择适当的选项(据我所知,它正在按照我的编码方式工作),然后提交表单就像我点击了执行操作按钮一样。

My current code is:我目前的代码是:

$(document).ready( function() {

    var topbar = $('#threadtools').closest('tr');
    var newTool = '<td><a href="#" id="newClose" style="padding-left: 10px; padding-right: 10px;"><b>Close</b></a></td>' +
                    '<td><a href="http://google.com" id="newMove"><b>Move</b></a></td>'; // Google for testing purposes I wanted to make sure preventDefault was working
    topbar.append(newTool);

    $('#newClose').click(function() { 
        alert();
    });
    $('#newMove').click(function(event) { 
        event.preventDefault();
        //var form = $('input[name$="threadadminform"]');  // select form by name
        var button = $('input[value="Perform Action"]');   // select button by name


        var closeradio = $('#ao_oct');
        var moveradio = $('#ao_mvt');
        var copyradio = $('#ao_cpt');
        var editradio = $('#ao_edt');
        var deleteradio = $('#ao_dlt');
        var stickradio = $('#ao_sut');
        var mergeradio = $('#ao_mgt');
        var redirectradio = $('#ao_rrd');

        closeradio.removeAttr('checked');
        copyradio.removeAttr('checked');
        editradio.removeAttr('checked');
        deleteradio.removeAttr('checked');
        stickradio.removeAttr('checked');
        mergeradio.removeAttr('checked');
        redirectradio.removeAttr('checked');

        moveradio.attr('checked', 'checked');
        button.trigger();
    });
});

As you can see I am currently trying to .trigger() the submit button, this does not work.如您所见,我目前正在尝试.trigger()提交按钮,这不起作用。
I have also tried .submit() on the form var I declared at the top, this also does not work.我也在顶部声明的表单 var 上尝试了.submit() ,这也不起作用。

How can I get this to submit as it would if I clicked the button and take me to the next appropriate page?如果我单击按钮并将我带到下一个适当的页面,我如何才能让它提交?

trigger needs a minimum of event, so you need to pass button.trigger('click') so that it will be able to perform the click event.触发器需要最少的事件,因此您需要传递 button.trigger('click') 以便它能够执行点击事件。

Sample demo of what you are trying to achieve is at , take a look at two button example at the above location.您尝试实现的示例演示位于,请查看上述位置的两个按钮示例。

hope this helps.希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM