我有一个页面,其中有一个表格,其中有两个单选按钮,在选中相关按钮的开启时,它的相关内容将显示在表格上。
<tr class="text">
<td colspan="4" valign="top" bgcolor="f2f2f2">
<?php
$srl=mysql_query("select * from module ORDER BY module_id ASC");
while($rows=mysql_fetch_array($srl))
{ ?>
<input type="radio" name="module" value=<?php echo $rows[module_id] ?>><?php echo $rows[module_name] ?>
<?php
}
?>
</td>
</tr>
</tbody>
</table>
<tr class="text">
<td colspan="6">
<div id="items_list"></div>
</tr>
我已经为api调用写了这个jquery。
<script type="text/javascript">
$(function() {
$("module").change(function() {
var module_id = $(this);
var dataString = 'module_id='+ module_id.val();
alert(dataString);
$("#items_list").html("");
if(module_id.val()=='')
{
alert("select stock type");
}
else {
$.ajax({
type: "POST",
url: "ajax/request_fetch_items.php",
data: dataString,
cache: false,
success: function(){
$("#items_list").html( html );
},
error:function (xhr, ajaxOptions, thrownError){
//On error, we alert user
alert(thrownError);
}
});
}
return false;
});
});
</script>
但是当我选择任何单选按钮时没有任何反应,它也没有在jquery中显示警报。 我想要的是每当选择一个单选按钮,其值通过ajax调用传递,剩余的html内容将加载到下一行。
在点击单选按钮时,它会显示以下代码,
<input type="radio" name="module" value="1">Stationary
<input type="radio" name="module" value="2">Inventory
答案 0 :(得分:3)
您的jQuery选择器$("module")
定位<module>
个html代码,只需将其更改为$("input[name=module]:radio")
,以便定位到名为module的无线电类型的<input>
元素。