做一个练习碰到了问题
index.php<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style>
#searchResult{width:920px;height:400px; OVERFLOW: scroll; OVERFLOW-X: hidden; border:1px dotted black; margin-top:1px;background-color:#00f600; }
</style>
<script>
var cur_id_no;
var xmlhttp;
var baseURl="show.php";
function $(str){return (document.getElementById(str));}
function getXMLRequester(){
var xmlhttp_request=false;
try{
if(window.ActiveXObject) {
for (var i=5;i>-1;i--){
try{
if (i==2){
xmlhttp_request=new ActiveXObject("Microsoft.XMLHTTP");
}else{
xmlhttp_request=new ActiveXObject("Msxml2.XMLHTTP."+i+".0");
}
break;
}catch(e){
xmlhttp_reques=false;
}
}
}else if (window.XMLHttpRequest) {
xmlhttp_request=new XMLHttpRequest();
}
}catch(e){
xmlhttp_request=false;
}
return xmlhttp_request;
}function start_search(){
xmlhttp=getXMLRequester();
xmlhttp.onreadystatechange=xmlhttp_onreadystatechange;
xmlhttp.open("GET",baseURl,true);
xmlhttp.send(" ");
}function xmlhttp_onreadystatechange(){
if(xmlhttp.readyState==4){
if(xmlhttp.status==200){
$("searchResult").innerHTML=xmlhttp.responseText;
}else{
$("searchResult").innerHTML="载入失败,返回码:"+xmlhttp.status;
}
}else{
$("searchResult").innerHTML="载入中,当前状态:"+xmlhttp.readyState;
}
}function start_edit(){
alert ($("on_sele_radio").value);
}
window.onload= function(){
$("cmd_search").onclick=start_search;
start_search();
}
</script>
</head>
<body>
<DIV id="searchBar">
<input id="cmd_search" type="button" onclick= "start_search()" value="刷新"/>
<input id="cmd_edit" type="button" onclick= "start_edit()" value="修改"/></DIV>
<div id="searchResult"></div>
</body>
</html>
show.php<?
$mysql_server_name = "localhost";
$mysql_username = "root";
$mysql_password = "123456";
$mysql_database = "gbook";
$sql = "SELECT * FROM gbook ORDER BY 'id' DESC"; //排序 后留言的在前面显示
$conn = mysql_connect($mysql_server_name,$mysql_username,$mysql_password);
mysql_query("set names utf8;");
mysql_select_db($mysql_database,$conn);
$result = mysql_query($sql);
?>
<table width="800" border="1">
<th width="170">日期时间</th>
<th width="80">IP</th>
<th width="80">姓名</th>
<th>性别</th>
<th width="100" >Email地址</th>
<th width="180">留言内容</th>
<th>选择</th><?
while($row = mysql_fetch_row($result))
{ // ----if语句判断男女------
if($row[2]==1)
{ $gender = '男';}
else
{ $gender = '女'; }
?>
<tr>
<td> <p><?=$row[6]?> <p></td>
<td> <p> <?=$row[5]?> </p> </td>
<td> <p><?=$row[1]?><p> </td>
<td> <p><?=$gender?> <p></td>
<td> <p> <?=$row[3]?></p></td>
<td> <p><?=nl2br($row[4])?><p></td>
<td> <p><input id="on_sele_radio" type="Radio" value=<?$row[0]?> > <?=$row[0]?>
</p>
</td>
</tr>
<?
}
mysql_free_result($result);
?>
</table>
如何在修改按钮绑定的事件中获得单选框的值.
现在的情况是提示一个惊叹号, 无任何内容AjaxJavaScript
index.php<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style>
#searchResult{width:920px;height:400px; OVERFLOW: scroll; OVERFLOW-X: hidden; border:1px dotted black; margin-top:1px;background-color:#00f600; }
</style>
<script>
var cur_id_no;
var xmlhttp;
var baseURl="show.php";
function $(str){return (document.getElementById(str));}
function getXMLRequester(){
var xmlhttp_request=false;
try{
if(window.ActiveXObject) {
for (var i=5;i>-1;i--){
try{
if (i==2){
xmlhttp_request=new ActiveXObject("Microsoft.XMLHTTP");
}else{
xmlhttp_request=new ActiveXObject("Msxml2.XMLHTTP."+i+".0");
}
break;
}catch(e){
xmlhttp_reques=false;
}
}
}else if (window.XMLHttpRequest) {
xmlhttp_request=new XMLHttpRequest();
}
}catch(e){
xmlhttp_request=false;
}
return xmlhttp_request;
}function start_search(){
xmlhttp=getXMLRequester();
xmlhttp.onreadystatechange=xmlhttp_onreadystatechange;
xmlhttp.open("GET",baseURl,true);
xmlhttp.send(" ");
}function xmlhttp_onreadystatechange(){
if(xmlhttp.readyState==4){
if(xmlhttp.status==200){
$("searchResult").innerHTML=xmlhttp.responseText;
}else{
$("searchResult").innerHTML="载入失败,返回码:"+xmlhttp.status;
}
}else{
$("searchResult").innerHTML="载入中,当前状态:"+xmlhttp.readyState;
}
}function start_edit(){
alert ($("on_sele_radio").value);
}
window.onload= function(){
$("cmd_search").onclick=start_search;
start_search();
}
</script>
</head>
<body>
<DIV id="searchBar">
<input id="cmd_search" type="button" onclick= "start_search()" value="刷新"/>
<input id="cmd_edit" type="button" onclick= "start_edit()" value="修改"/></DIV>
<div id="searchResult"></div>
</body>
</html>
show.php<?
$mysql_server_name = "localhost";
$mysql_username = "root";
$mysql_password = "123456";
$mysql_database = "gbook";
$sql = "SELECT * FROM gbook ORDER BY 'id' DESC"; //排序 后留言的在前面显示
$conn = mysql_connect($mysql_server_name,$mysql_username,$mysql_password);
mysql_query("set names utf8;");
mysql_select_db($mysql_database,$conn);
$result = mysql_query($sql);
?>
<table width="800" border="1">
<th width="170">日期时间</th>
<th width="80">IP</th>
<th width="80">姓名</th>
<th>性别</th>
<th width="100" >Email地址</th>
<th width="180">留言内容</th>
<th>选择</th><?
while($row = mysql_fetch_row($result))
{ // ----if语句判断男女------
if($row[2]==1)
{ $gender = '男';}
else
{ $gender = '女'; }
?>
<tr>
<td> <p><?=$row[6]?> <p></td>
<td> <p> <?=$row[5]?> </p> </td>
<td> <p><?=$row[1]?><p> </td>
<td> <p><?=$gender?> <p></td>
<td> <p> <?=$row[3]?></p></td>
<td> <p><?=nl2br($row[4])?><p></td>
<td> <p><input id="on_sele_radio" type="Radio" value=<?$row[0]?> > <?=$row[0]?>
</p>
</td>
</tr>
<?
}
mysql_free_result($result);
?>
</table>
如何在修改按钮绑定的事件中获得单选框的值.
现在的情况是提示一个惊叹号, 无任何内容AjaxJavaScript
具体可参考我的开源项目,里面分页什么的都是用基于jQuery的ajax请求实例
http://blog.csdn.net/shadowsick
Ext.getCmp(id).getValue();
教材上说, 把一组单选框的名字相同, 可以得到一个一个对象. 进而可以得到一个字值, 景测试发现 , 只有在东一个节点下的单选框组踩有效, 不再统一节点下的是无效的. 比如上面这个练习中, 各个选项在表格的各行, 就不行了. 有NAME存取只能得到第一个值的内容, 是不是这样呢?
2、你的单选钮都使用了相同的 id,违背了 id 唯一性原则
所以你的 start_edit 只能取得第一个单选钮的值
3、判断一个单选钮是否被选中,不能简单的读取单选钮的值(这一点与服务器端不同),因为 value 始终都是存在的。而是要遍历所有同名单选钮,逐一检查 checked 属性是否为真,为真的才是被选中的
是不是,使用不同的ID 相同的name,才能取得 根据name 获取单选按钮组的的值呢;
如果必须经过遍历来检查checked, 那就太麻烦了. 如果记录很多,效率太低了
http://bbs.csdn.net/topics/390460403?page=1#post-394504595
希望各位帮帮忙看看