我有一个页面,上面有一个表单,里面有两个单选按钮,选中相关按钮中的一个,它的相关内容就会显示在表单上。
<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
最佳答案
你的 jQuery 选择器 $("module")
目标 <module>
html标签,改成$("input[name=module]:radio")
即可所以它的目标是<input>
radio 命名模块类型的元素。
关于php - 查询从多个表中获取数据 MySQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28427834/