使用jQuery检查<radio>时如何更改<form>的“动作”?

omg*_*omg 3 jquery event-handling

<form action="1.html">
    <input type="radio" id="check1" name="check" />
    <input type="radio" id="check2" name="check" />
</form>
Run Code Online (Sandbox Code Playgroud)

我想要实现的是:

选中“check2”时,将“action”值更改为“2.html”

检查“Check1”时,将“动作”值更改为“1.html”

Cha*_*ion 5

这应该可以解决您的问题。

$(function(){
    $('#check1').click(function() {
        $(this).parent().attr('action', '1.html');
    });

    $('#check2').click(function() {
        $(this).parent().attr('action', '2.html');
    });
});
Run Code Online (Sandbox Code Playgroud)