DropdownList change 事件只触发一次?jQuery代码:JScript code$(document).ready(function(){//获取项目下
DropdownList change 事件只触发一次?
jQuery代码:
JScript code$(document).ready(function(){ //获取项目下拉框的值(项目编号) var ddlxm=$("#<%=drpXMName.ClientID %>"); ddlxm.change(function(){ $.post( "../ajax/GetHTByObjHandler.ashx", {xmNumber:$('#<%=drpXMName.ClientID %> option:selected').val()}, function(results){ $("#divht").val(results); }),"html"; }) })
Haddler代码:
C# codecontext.Response.ContentType = "text/html"; //读取传过来的项目 string xmNumber = context.Request.QueryString["xmNumber"]; HTBLL bll = new HTBLL(); IList<Tb_HTInfo> list = bll.GetHTMessageByObjNumber(xmNumber); StringBuilder sd = new StringBuilder(); sd.Append("<select id=\"ddlHT\"> runat=\"server\""); sd.Append("<option value=\"--请选择--\" selected=\"selected\">--请选择--</option>"); if (list.Count > 0) { for (int i = 0; i < list.Count; i++) { sd.Append("<option value=\""+list[i].Ht_HTnumber+"\" selected=\"selected\">"+list[i].Ht_HTName+"</option>"); } } sd.Append("</select>"); context.Response.Write(sd);
为什么第一次会触发下拉框的change事件并且进入到Haddler里面,可是只会进入一次?后面就不再触发change事件了?是怎么回事?还是说一般不用change事件来实现这个功能?那用哪个事件?求高手,在线等
[解决办法]把ddlxm.change单拿出来,不写在ready里
[解决办法]<!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>
<title></title>
<script src="js/jquery-1.7.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
$().ready(function () {
$("#Select1").change(
function () {
alert(123);
}
);
});
</script>
</head>
<body>
<select id="Select1">
<option> 1</option>
<option> 2</option>
</select>
</body>
</html>
[解决办法] $().ready(function () {
$("#Select1").change(
function () {
$.post(
"../ajax/GetHTByObjHandler.ashx",
{xmNumber:$('#<%=drpXMName.ClientID %> option:selected').val()},
function(results){
$("#divht").val(results);
}),"html";
}
);
});
[解决办法]<script>
$(document).ready(function(){
});
$("#<%=drpXMName.ClientID %>").change(function(){
$.post(
"../ajax/GetHTByObjHandler.ashx",
{xmNumber:$('#<%=drpXMName.ClientID %> option:selected').val()},
function(results){
$("#divht").val(results);
}),"html";
})
</script>
试下....仅供参考,我好久没碰Jquery了
[解决办法]
"../ajax/GetHTByObjHandler.ashx?test="+ new Date().getTime(),
改成这样试试