用js怎么判断dropdownlist的值改变? 比如 dropdownlist里面有三个值 a、b、c 第一次选值的时候不提示,如果现在有个值是a,当我在选值b时,则提示是否改变其值? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 $("#DropDownListID").bind("change", function() { // 当选择改变是发生}); 这是我的jsfunction OnCurrentYearProfitAccoutRefChangedHandler(grid, ev){var dto = ev.value; // 得到控件 var comboCtl=document.getElementById("CurrentYearProfitAccout"); // 得到控件值 var dto=comboCtl.value; if(dto.length!=0) { //在这里面写 改怎么写啊 } var grid=this.getGrid(); grid.endEdit(); for(var i=0;i<grid.rowCount;i++) { grid.setCellValue(i,"ProfitAccount_Code",dto.Code); //grid.setCellValue(i,"ProfitAccount",dto.Name); //grid.setCellValue(i,"idprofitAccount",dto.ID); grid.setRefValue(grid.getCol("ProfitAccount"), dto, i); } } <script language="javascript"> function Change() { var vValue=document.all('DropDownList1').value; alert(vValue);}</script> <asp:DropDownList ID="DropDownList1" runat="server" Width="253px" AutoPostBack="false" onchange="Change();" Height="20px" > <asp:ListItem Value="a">a</asp:ListItem> <asp:ListItem Value="b">b</asp:ListItem> <asp:ListItem Value="b">c</asp:ListItem></asp:DropDownList> 开始的时候change事件绑定到一个方法a,在方法a里将dropdownlist的事件绑定解除,再绑定到方法b,方法b里做你要多提示。这样第一次就不提示了 dropdownList就是select. <select id="Select1" onchange="change(this);"> <option value="1">1</option> <option value="2">2</option> </select><script>var index=0;function change(src){ if(window.confirm()) { index=src.selectedIndex; } else { src.selectedIndex=index; } } </script> jquery:$("#DropDownListID").change(function() { // 事件处理}); 额,看来也不用这么麻烦了,页面定义一个的flag变量,事件执行的时候,判断flag,看是否要提示,若是则提示,否则把flag改掉 dropdownList就是select.<asp:DropDownList ID="DropDownList1" runat="server" Width="253px" AutoPostBack="false" onchange="change(this);" Height="20px" > <asp:ListItem Value="a">a</asp:ListItem> <asp:ListItem Value="b">b</asp:ListItem> <asp:ListItem Value="b">c</asp:ListItem></asp:DropDownList><script>var index=0;function change(src){ if(window.confirm("是否改变")) { index=src.selectedIndex; } else { src.selectedIndex=index; } } </script> jquery:$("#DropDownListID").change(function() { // 事件处理}); $(function() { // 初始化 var iCount = 0; var iSelValue = $("#DropDownListID").val(); // 绑定事件 $("#DropDownListID").bind("change", function() { if (iCount > 0 && iSelValue != $(this).val()) { // 第二次改变了 } iCount++; iSelValue = $(this).val(); });}); this.CurrentYearProfitAccout.OnRefChanged = "OnCurrentYearProfitAccoutRefChangedHandler";这就是我的事件 你说错了实际上不一样的 因为没有ONCHANGE这个方法实验下行吗 手写onchange,应该没问题吧,<select>是不是有onchange? function OnCurrentYearProfitAccoutRefChangedHandler(grid, ev){var dto = ev.value; // 得到控件 var comboCtl=document.getElementById("CurrentYearProfitAccout"); // 得到控件值 var dto=comboCtl.value; if(dto.length!=0) { //在这里面写 改怎么写啊 } var grid=this.getGrid(); grid.endEdit(); for(var i=0;i<grid.rowCount;i++) { grid.setCellValue(i,"ProfitAccount_Code",dto.Code); //grid.setCellValue(i,"ProfitAccount",dto.Name); //grid.setCellValue(i,"idprofitAccount",dto.ID); grid.setRefValue(grid.getCol("ProfitAccount"), dto, i); } }其他的都不要管了 就在这里面写 。 <SELECT id=select onchange=window.open(this.options[this.selectedIndex].value,'','') size=1 name=select> <%GetDaoH("4");%> <script>var flag=false;</script>if(dto.length!=0) { if(flag){alert('改了!');}else{flag=true;} } 都说了 没有change事件 晕死 都不看 你这个flag 什么意思?直接在html页面定义 然后在js引用 怎么引用啊 能引用的到吗?这就是我的控件 <cc1:RefComboBox ID="CurrentYearProfitAccout" DropDownPanelID="DropDownComboList1" runat="server" AutoLoadData="true" DropDownStyle="DropDownGrid" RefDataSource="AccountDTO" AllowEdit="true" AllowInput="true" AllowAdd="true" RefObject="AccountDTO" RefPage="~/CommonPage/RefPage.aspx" ControlType="RefComboBox" /> 没有change事件 你只是不能单击出来而已,但是你如果写了onchange事件,是不会报错的,因为DropDownList在编译的时候就是将编译为Select的 2个Lable的值能比较吗? 如何在GridView中的最后一行写:合计:功能,高手进来指教!谢谢 有哪位能够提供一份web开发的需求文档,小弟100分倾囊相授了 怎么写展开,收缩的blog代码? 转换XML字符串[简单问题] 用JavaScript怎么动态添加控件??? 用c# 如何操作 iis 根目录 有个工作机会大家来看看! iframe(内嵌框架)调用页面问题 怎么把xml的内容绑定到数据控件内 未将对象引用设置到对象的实例 在web上创建好了DataTable 要显示在页面上 怎么办
// 当选择改变是发生
});
{
var dto = ev.value; // 得到控件
var comboCtl=document.getElementById("CurrentYearProfitAccout");
// 得到控件值
var dto=comboCtl.value;
if(dto.length!=0)
{
//在这里面写 改怎么写啊
} var grid=this.getGrid();
grid.endEdit();
for(var i=0;i<grid.rowCount;i++)
{
grid.setCellValue(i,"ProfitAccount_Code",dto.Code);
//grid.setCellValue(i,"ProfitAccount",dto.Name);
//grid.setCellValue(i,"idprofitAccount",dto.ID);
grid.setRefValue(grid.getCol("ProfitAccount"), dto, i);
}
}
function Change()
{
var vValue=document.all('DropDownList1').value;
alert(vValue);
}
</script>
<asp:DropDownList ID="DropDownList1" runat="server" Width="253px" AutoPostBack="false" onchange="Change();" Height="20px" >
<asp:ListItem Value="a">a</asp:ListItem>
<asp:ListItem Value="b">b</asp:ListItem>
<asp:ListItem Value="b">c</asp:ListItem>
</asp:DropDownList>
<option value="1">1</option>
<option value="2">2</option>
</select><script>
var index=0;
function change(src)
{
if(window.confirm())
{
index=src.selectedIndex;
}
else
{
src.selectedIndex=index;
}
}
</script>
$("#DropDownListID").change(function() {
// 事件处理
});
<asp:ListItem Value="a">a</asp:ListItem>
<asp:ListItem Value="b">b</asp:ListItem>
<asp:ListItem Value="b">c</asp:ListItem>
</asp:DropDownList><script>
var index=0;
function change(src)
{
if(window.confirm("是否改变"))
{
index=src.selectedIndex;
}
else
{
src.selectedIndex=index;
}
}
</script>
$("#DropDownListID").change(function() {
// 事件处理
});
// 初始化
var iCount = 0;
var iSelValue = $("#DropDownListID").val(); // 绑定事件
$("#DropDownListID").bind("change", function() {
if (iCount > 0 && iSelValue != $(this).val()) {
// 第二次改变了
} iCount++;
iSelValue = $(this).val();
});
});
这就是我的事件
实际上不一样的 因为没有ONCHANGE这个方法
实验下行吗
{
var dto = ev.value; // 得到控件
var comboCtl=document.getElementById("CurrentYearProfitAccout");
// 得到控件值
var dto=comboCtl.value;
if(dto.length!=0)
{
//在这里面写 改怎么写啊
} var grid=this.getGrid();
grid.endEdit();
for(var i=0;i<grid.rowCount;i++)
{
grid.setCellValue(i,"ProfitAccount_Code",dto.Code);
//grid.setCellValue(i,"ProfitAccount",dto.Name);
//grid.setCellValue(i,"idprofitAccount",dto.ID);
grid.setRefValue(grid.getCol("ProfitAccount"), dto, i);
}
}
其他的都不要管了 就在这里面写 。
onchange=window.open(this.options[this.selectedIndex].value,'','')
size=1 name=select> <%GetDaoH("4");%>
var flag=false;
</script>if(dto.length!=0)
{
if(flag){
alert('改了!');
}else{
flag=true;
} }
你这个flag 什么意思?直接在html页面定义 然后在js引用 怎么引用啊 能引用的到吗?这就是我的控件
<cc1:RefComboBox ID="CurrentYearProfitAccout"
DropDownPanelID="DropDownComboList1"
runat="server"
AutoLoadData="true"
DropDownStyle="DropDownGrid"
RefDataSource="AccountDTO"
AllowEdit="true"
AllowInput="true"
AllowAdd="true"
RefObject="AccountDTO"
RefPage="~/CommonPage/RefPage.aspx"
ControlType="RefComboBox"
/> 没有change事件