单选按钮jQuery更改不起作用

时间:2022-11-20 14:31:09

sorry if this is a repost, I've looked around and cannot find a solution that works.

对不起,如果这是一个转贴,我环顾四周,找不到有效的解决方案。

I have to radio buttons, and I want to execute a function when they are changed. From other posts I thought this should work

我需要单选按钮,我想在更改时执行一个功能。从其他帖子我认为这应该工作

$(function() {
    $("#isMale").change( function() {
        alert("test");
        location.href = 'http://google.com'
    }
});

http://jsfiddle.net/BfMYF/1/

But it doesn't, can anyone help ?

但它没有,任何人都可以帮忙吗?

2 个解决方案

#1


5  

The selector is wrong, but you need to close .change function brackets properly too:

选择器是错误的,但您也需要正确关闭.change功能括号:

$(function() {
    $("input[name=isMale]").change( function() {
        alert("test");
        location.href = 'http://google.com';
    });
});

#2


0  

$(function() {
    $("#male,#female").change(function () {
        alert("test");
        location.href = 'http://google.com';
    });
});

You also had a missing semi and paran!

你也有一个失踪的半和paran!

#1


5  

The selector is wrong, but you need to close .change function brackets properly too:

选择器是错误的,但您也需要正确关闭.change功能括号:

$(function() {
    $("input[name=isMale]").change( function() {
        alert("test");
        location.href = 'http://google.com';
    });
});

#2


0  

$(function() {
    $("#male,#female").change(function () {
        alert("test");
        location.href = 'http://google.com';
    });
});

You also had a missing semi and paran!

你也有一个失踪的半和paran!