首页 >后端开发 >php教程 >php+jquery做onchange提交动作的问题,请人帮忙看看

php+jquery做onchange提交动作的问题,请人帮忙看看

WBOY
WBOY原创
2016-06-23 14:19:23941浏览

PHP jQuery onchange

我有个列表出来的结果,每列都有个onchange的动作,可是只有第一行的onchange可以操作,其他都没有反应,不知道怎么回事。
 <?	include("../config.inc.php");		//医生排班列表开始	$strDoctorTime = "";	if( isset($_REQUEST['Action']) && !empty($_REQUEST['Action']) && ($_REQUEST['Action'] == "setdoctortime") ){						$sqlDoctorTime = "select sid,doctorid,CONVERT(varchar(100), starttime, 20) as starttime,CONVERT(varchar(100), endtime, 120) as endtime,duration,createtime,type,operid,status,visits_counts,original_counts,istrue from gst_scheduling where doctorid = '".$_REQUEST['doctorid']."' ";		//if ( (isset($_REQUEST['starttime']) && !empty($_REQUEST['starttime'])) && (isset($_REQUEST['endtime']) && !empty($_REQUEST['endtime']))  ) {		//	$sqlDoctorTime .= " ";		//}		$sqlDoctorTime .= " order by sid desc";		$resDoctorTime = $SqlDB->Query($sqlDoctorTime);		$arrDoctorTime = $SqlDB->getRows($resDoctorTime);						for($i=0; $i<count($arrDoctorTime); $i++) {			$strSelectStatus = ""; //初始号源下拉值			$strSelectStatus  = "<select name=\"originalcounts\" id=\"originalcounts\">";			$strSelectStatus .= "<option value=\"1|".$arrDoctorTime[$i]['sid']."\" ";			if(trim($arrDoctorTime[$i]['original_counts']) == "1") $strSelectStatus .=  ' selected';			$strSelectStatus .= ">1</option>";			$strSelectStatus .= "<option value=\"2|".$arrDoctorTime[$i]['sid']."\" ";			if(trim($arrDoctorTime[$i]['original_counts']) == "2") $strSelectStatus .=  ' selected';			$strSelectStatus .= ">2</option>";			$strSelectStatus .= "<option value=\"3|".$arrDoctorTime[$i]['sid']."\" ";			if(trim($arrDoctorTime[$i]['original_counts']) == "3") $strSelectStatus .=  ' selected';			$strSelectStatus .= ">3</option>";			$strSelectStatus .= "<option value=\"4|".$arrDoctorTime[$i]['sid']."\" ";			if(trim($arrDoctorTime[$i]['original_counts']) == "4") $strSelectStatus .=  ' selected';			$strSelectStatus .= ">4</option>";			$strSelectStatus .= "<option value=\"5|".$arrDoctorTime[$i]['sid']."\" ";			if(trim($arrDoctorTime[$i]['original_counts']) == "5") $strSelectStatus .=  ' selected';			$strSelectStatus .= ">5</option>";			$strSelectStatus .= "<option value=\"6|".$arrDoctorTime[$i]['sid']."\" ";			if(trim($arrDoctorTime[$i]['original_counts']) == "6") $strSelectStatus .=  ' selected';			$strSelectStatus .= ">6</option>";			$strSelectStatus .= "<option value=\"7|".$arrDoctorTime[$i]['sid']."\" ";			if(trim($arrDoctorTime[$i]['original_counts']) == "7") $strSelectStatus .=  ' selected';			$strSelectStatus .= ">7</option>";			$strSelectStatus .= "<option value=\"8|".$arrDoctorTime[$i]['sid']."\" ";			if(trim($arrDoctorTime[$i]['original_counts']) == "8") $strSelectStatus .=  ' selected';			$strSelectStatus .= ">8</option>";			$strSelectStatus .= "<option value=\"9|".$arrDoctorTime[$i]['sid']."\" ";			if(trim($arrDoctorTime[$i]['original_counts']) == "9") $strSelectStatus .=  ' selected';			$strSelectStatus .= ">9</option>";			$strSelectStatus .= "<option value=\"10|".$arrDoctorTime[$i]['original_counts']."\" ";			if(trim($arrDoctorTime[$i]['original_counts']) == "10") $strSelectStatus .=  ' selected';			$strSelectStatus .= ">10</option>";			$strSelectStatus .= "</select>";		}	}	//医生排班列表结束		?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML><HEAD><title></title><META http-equiv=Content-Type content="text/html; charset=gb2312"><LINK href="/css/admin.css" type="text/css" rel="stylesheet"></HEAD><script src="js/jquery-1.5.2.min.js" type="text/javascript"></script><script language="javascript" type="text/javascript" src="http://www.360gst.com/datepicker/WdatePicker.js"></script><script type="text/javascript">   	$(document).ready(function(){		  $('#originalcounts').change(function(){		alert("33333");		if(!confirm('确定提交')) return;		var p1 = $(this).val();		alert(p1);		$("#originalcounts").attr("disabled","disabled");		postdata(p1);		$("#originalcounts").attr("disabled","");	  });     	});    	function postdata(p1){		alert(p1);	alert("222");	  $("#loading").fadeOut("slow")	  $.ajax({		type: "POST",               		url: "ajax_changedoctorcount.php",              		data: "sid="+p1,    				beforeSend:function(XMLHttpRequest){			//$("#showResult").text("数据更新中,请稍后.......");			$("#showResult").html('<img  src="images/ajax-loader-eeeeee.gif" alt="php+jquery做onchange提交动作的问题,请人帮忙看看" >Loading...');  			//show loading images			//Pause(this,100000);  		},		success: function(msg){		  //ajaxCheckRes(msg);		  //alert(msg);		  //alert("11111111");		  //$("#showResult").html(msg);		  //$("#showResult").css("color","red"); 		  //$(Element).removeClass("loading");		  alert("message:"+msg);		  $("#showResult").hide();		  if( msg == "ok1" ) {			alert("数据提交成功"); //如果有必要,可以把msg变量的值显示到某个DIV元素中					  }		  		  if( msg == "error" ) {			  alert("订单编号丢失"); //如果有必要,可以把msg变量的值显示到某个DIV元素中		  }		  		  //无论Ajax是否成功执行都会触发的回调函数		  complete:function(XMLHttpRequest,textStatus){			  //隐藏正在查询图片			 //window.location.href = location.href;		  }		  window.location.href = location.href ;		  error: function() { alert("error"); }  		}     			  });	  	}		//异步处理返回数据	//function ajaxCheckRes(data){	//	document.getElementById(innerdiv).innerHTML = data;	//}		//重新加载页面	/*function getdigshtml() {		$.ajax({			type:'POST',			url:'customservice.php',			data:'',			success:function(msg){				$("#digg").html(msg);			}		})	}*/</script><script src="js/jquery-1.5.2.min.js" type="text/javascript"></script><BODY><TABLE cellSpacing=0 cellPadding=0 width="95%" align=center border=0>  <TR    style="max-width:90%">    <TD> </TD>  </TR></TABLE><table width="95%" align="center" border="0" cellpadding="0" cellspacing="1" bgcolor="b5d6e6">	<tr background="../images/bg.gif" bgcolor="#FFFFFF">		<th scope="row"  background="../images/bg.gif" bgcolor="#FFFFFF">开始时间:</th>		<td  background="../images/bg.gif" bgcolor="#FFFFFF">			<input id="starttime" onClick="WdatePicker()" type="text" name="starttime" class="textfield"><span style="color: #FF0000">(*)</span> 		</td>		<th scope="row"  background="../images/bg.gif" bgcolor="#FFFFFF">开始时间:</th>		<td  background="../images/bg.gif" bgcolor="#FFFFFF">			<input id="endtime" onClick="WdatePicker()" type="text" name="endtime" class="textfield" onfocus="WdatePicker()"><span style="color: #FF0000">(*)</span>		 		</td>	</tr>	<tr  background="../images/bg.gif" bgcolor="#FFFFFF">		<th colspan="4" scope="row">			<label>				<input type="submit" name="Submit" value="查询医生排期" />            </label>		</form>		</th>	</tr></table><TABLE cellSpacing=0 cellPadding=0 width="95%" align=center border=0>  <TR height=20>    <TD> </TD></TR></TABLE><table width="95%" align="center" border="0" cellpadding="0" cellspacing="1" bgcolor="b5d6e6" onMouseOver="changeto()"  onmouseout="changeback()">	  <tr>		<td width="8%" height="22" background="../images/bg.gif" bgcolor="#FFFFFF"><div align="center">1医生</div></td>		<td width="8%" height="22" background="../images/bg.gif" bgcolor="#FFFFFF"><div align="center">开始时间</div></td>		<td width="8%" height="22" background="../images/bg.gif" bgcolor="#FFFFFF" class="STYLE1"><div align="center">结束时间</div></td>		<td width="5%" height="22" background="../images/bg.gif" bgcolor="#FFFFFF"><div align="center">排期间隔</div></td>		<td width="5%" height="22" background="../images/bg.gif" bgcolor="#FFFFFF"><div align="center">初始号源数</div></td>		<td width="5%" height="22" background="../images/bg.gif" bgcolor="#FFFFFF"><div align="center">剩余号源数</div></td>		<td width="5%" height="22" background="../images/bg.gif" bgcolor="#FFFFFF"><div align="center">是否出诊</div></td>		<td width="5%" height="22" background="../images/bg.gif" bgcolor="#FFFFFF"><div align="center">类别</div></td>		<td width="4%" height="22" background="../images/bg.gif" bgcolor="#FFFFFF"><div align="center">操作员</div></td>		<td width="8%" height="22" background="../images/bg.gif" bgcolor="#FFFFFF"><div align="center">操作</div></td>	  </tr>	  <?=$strDoctorTime;?></table><?	}	?></BODY></HTML><?$SqlDB->Close();?>

回复讨论(解决方案)

id 重复了吧,贴出HTML源码出来看看。

 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML><HEAD><title>固生堂客服系统V1.0</title><META http-equiv=Content-Type content="text/html; charset=gb2312"><LINK href="/css/admin.css" type="text/css" rel="stylesheet"></HEAD><script src="js/jquery-1.5.2.min.js" type="text/javascript"></script><script language="javascript" type="text/javascript" src="http://www.360gst.com/datepicker/WdatePicker.js"></script><script src="js/jquery-1.5.2.min.js" type="text/javascript"></script> <BODY><TABLE cellSpacing=0 cellPadding=0 width="95%" align=center border=0>  <TR height="5">    <TD></TD></TR>  <TR height="22">    <TD style="PADDING-LEFT: 20px; FONT-WEIGHT: bold; COLOR: #ffffff" align="middle" background="/images/title_bg2.jpg">目前正在使用系统的工号:0017-万辉,  <A style="COLOR: #fff" onclick="if (confirm('确定要退出吗?')) return true; else return false;" href="/logout.php" target="_top">退出系统</A></TD></TR>    <TR height="10">    <TD></TD></TR></TABLE><TABLE cellSpacing=0 cellPadding=0 width="95%" align=center border=0>  <TR height=20>    <TD> </TD></TR></TABLE><TABLE cellpadding="0" cellspacing="1" width="95%" align="center" border="0">  <tr align="center">    <!--<td bgColor="#b1ceef" width="18%"><a href="customservice.php?Action=customerConsumption">客户消费</a></td>	<td bgColor="#b1ceef" width="25%"><a href="customservice.php?Action=searchcard">查询客户理疗卡信息</a></td>    <td bgColor="#b1ceef" width="20%"><a href="customservice.php?Action=createinvdusercard">虚拟卡客户开卡</a></td>	<td bgColor="#b1ceef" width="18%"><a href="customservice.php?Action=createusercard">用户调理次卡开卡</a></td>-->	<td bgColor="#b1ceef" width="25%"><a href="customservice.php?Action=doctortime">医生排期设置</a></td>  </tr></table> <!--医生排期设置开始--><TABLE cellSpacing=0 cellPadding=0 width="95%" align=center border=0>  <TR height="20">    <TD> </TD>  </TR></TABLE><table width="95%" align="center" border="0" cellpadding="0" cellspacing="1" bgcolor="b5d6e6">	<tr background="../images/bg.gif" bgcolor="#FFFFFF">		<th scope="row"  background="../images/bg.gif" bgcolor="#FFFFFF">开始时间:</th>		<td  background="../images/bg.gif" bgcolor="#FFFFFF">			<input id="starttime" onClick="WdatePicker()" type="text" name="starttime" class="textfield"><span style="color: #FF0000">(*)</span> 		</td>		<th scope="row"  background="../images/bg.gif" bgcolor="#FFFFFF">开始时间:</th>		<td  background="../images/bg.gif" bgcolor="#FFFFFF">			<input id="endtime" onClick="WdatePicker()" type="text" name="endtime" class="textfield" onfocus="WdatePicker()"><span style="color: #FF0000">(*)</span>		 		</td>	</tr>	<tr  background="../images/bg.gif" bgcolor="#FFFFFF">		<th colspan="4" scope="row">			<label>				<input type="submit" name="Submit" value="查询医生排期" />            </label>		</form>		</th>	</tr></table><TABLE cellSpacing=0 cellPadding=0 width="95%" align=center border=0>  <TR height=20>    <TD> </TD></TR></TABLE><table width="95%" align="center" border="0" cellpadding="0" cellspacing="1" bgcolor="b5d6e6" onMouseOver="changeto()"  onmouseout="changeback()">	  <tr>		<td width="8%" height="22" background="../images/bg.gif" bgcolor="#FFFFFF"><div align="center">1医生</div></td>		<td width="8%" height="22" background="../images/bg.gif" bgcolor="#FFFFFF"><div align="center">开始时间</div></td>		<td width="8%" height="22" background="../images/bg.gif" bgcolor="#FFFFFF" class="STYLE1"><div align="center">结束时间</div></td>		<td width="5%" height="22" background="../images/bg.gif" bgcolor="#FFFFFF"><div align="center">排期间隔</div></td>		<td width="5%" height="22" background="../images/bg.gif" bgcolor="#FFFFFF"><div align="center">初始号源数</div></td>		<td width="5%" height="22" background="../images/bg.gif" bgcolor="#FFFFFF"><div align="center">剩余号源数</div></td>		<td width="5%" height="22" background="../images/bg.gif" bgcolor="#FFFFFF"><div align="center">是否出诊</div></td>		<td width="5%" height="22" background="../images/bg.gif" bgcolor="#FFFFFF"><div align="center">类别</div></td>		<td width="4%" height="22" background="../images/bg.gif" bgcolor="#FFFFFF"><div align="center">操作员</div></td>		<td width="8%" height="22" background="../images/bg.gif" bgcolor="#FFFFFF"><div align="center">操作</div></td>	  </tr>	  <tr> <td height="20" bgcolor="#FFFFFF"><div align="center"><span class="STYLE1">131 </span></div></td><td height="20" bgcolor="#FFFFFF"><div align="center"><span class="STYLE1">2013-07-06 17:00:00 </span></div></td><td height="20" bgcolor="#FFFFFF"><div align="center" class="STYLE1"><div align="center">2013-07-06 17:30:00 </div></div></td><td height="20" bgcolor="#FFFFFF"><div align="center" class="STYLE1"><div align="center">30分 </div></div></td><td bgcolor="#FFFFFF"><div align="center"><span class="STYLE1"><select name="originalcounts" id="originalcounts"><option value="1|12572" >1</option><option value="2|12572" >2</option><option value="3|12572"  selected>3</option><option value="4|12572" >4</option><option value="5|12572" >5</option><option value="6|12572" >6</option><option value="7|12572" >7</option><option value="8|12572" >8</option><option value="9|12572" >9</option><option value="10|3" >10</option></select> </span></div></td><td bgcolor="#FFFFFF"><div align="center"><span class="STYLE1">5 </span></div></td><td bgcolor="#FFFFFF"><div align="center"><span class="STYLE1">0 </span></div></td><td bgcolor="#FFFFFF"><div align="center"><span class="STYLE1">1 </span></div></td><td height="20" bgcolor="#FFFFFF"><div align="center" class="STYLE1"><div align="center">0017 </div></div></td><td height="20" bgcolor="#FFFFFF"><div align="center"><span class="STYLE1"><a href="/appointment/customservice.php?Action=deldoctortime&doctorid=131">删除</a></span></div></td> </tr><tr> <td height="20" bgcolor="#FFFFFF"><div align="center"><span class="STYLE1">131 </span></div></td><td height="20" bgcolor="#FFFFFF"><div align="center"><span class="STYLE1">2013-07-06 16:30:00 </span></div></td><td height="20" bgcolor="#FFFFFF"><div align="center" class="STYLE1"><div align="center">2013-07-06 17:00:00 </div></div></td><td height="20" bgcolor="#FFFFFF"><div align="center" class="STYLE1"><div align="center">30分 </div></div></td><td bgcolor="#FFFFFF"><div align="center"><span class="STYLE1"><select name="originalcounts" id="originalcounts"><option value="1|12571" >1</option><option value="2|12571" >2</option><option value="3|12571" >3</option><option value="4|12571" >4</option><option value="5|12571" >5</option><option value="6|12571"  selected>6</option><option value="7|12571" >7</option><option value="8|12571" >8</option><option value="9|12571" >9</option><option value="10|6" >10</option></select> </span></div></td><td bgcolor="#FFFFFF"><div align="center"><span class="STYLE1">6 </span></div></td><td bgcolor="#FFFFFF"><div align="center"><span class="STYLE1">0 </span></div></td><td bgcolor="#FFFFFF"><div align="center"><span class="STYLE1">1 </span></div></td><td height="20" bgcolor="#FFFFFF"><div align="center" class="STYLE1"><div align="center">0017 </div></div></td><td height="20" bgcolor="#FFFFFF"><div align="center"><span class="STYLE1"><a href="/appointment/customservice.php?Action=deldoctortime&doctorid=131">删除</a></span></div></td> </tr></table> <!--医生排期设置结束--></BODY></HTML>

楼上的,html已经贴出了

id 重复了,当然不行!

$('#originalcounts').change 可以改成用 $('.originalcounts').change

原来的selct都加上一个属性class="originalcounts"

楼上的请问下,改成这样的是不是id重复了就没问题呢?

有问题啊,如果我的select的id都不一样,下面js里面的属性该怎么写呢?
$strSelectStatus  = "

版主,请问下我该怎么修改一下呢?

把事件绑定到 select 上就可以了
测试例

<script>$(function() {  $('select').change(function(){    alert(this.name + ':' + $(this).val());  });});</script><select name=s1><option><option>A<option>B</select><select name=s2><option><option>A<option>B</select><select name=s3><option><option>A<option>B</select>

好了,谢谢!

to 版主:能给我解释一下下面这段是什么意思吗?
 

  //异步处理返回数据     //function ajaxCheckRes(data){     //    document.getElementById(innerdiv).innerHTML = data;     //}           //重新加载页面     /*function getdigshtml() {         $.ajax({             type:'POST',             url:'customservice.php',             data:'',             success:function(msg){                 $("#digg").html(msg);             }         })     }*/

to 版主,新问题出来了,如果这个页面上有2个SELECT元素,点任何一个SELECT都会触发。

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn