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# code
context.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);