0

我试图通过 Ajax 获取单选按钮字段的值,但它只返回'undefined'

我在用着:

function  fetch_data(id,type)
{
    $.ajax({
            type: "POST",
            async: false,
            url: "fetch_data.php",
            data: "id="+id+"&type="+type,
            success: function(msg){
                         $("#div1").html(msg);  
                     }
    });
}

<select name="data1" id="data1"
onchange="fetch_data(this.value,document.getElementsById('radio1').value"
style=" width:150px;"> 


<div id="div1"></div>

将替换为“fetch_data.php”页面 div

4

3 回答 3

2

检查您是否有radio1作为单选框的 ID 并替换document.getElementsByIddocument.getElementById

于 2012-04-11T05:51:38.933 回答
1

codef0rmer 是对的,您在编写 getElement* S *ById 的语法中有错误,但它在没有 S 的情况下称为 getElementById。

于 2012-04-11T05:59:09.613 回答
0

您可以尝试以下方法:

<select name="data1" id="data1" 
        onchange="fetch_data(this.value,"+document.getElementsById('radio1').value+""          
        style=" width:150px;">
于 2012-04-11T06:01:06.523 回答