Jquery 对asp.net dropdownlist控件更改进行计算
我有这个html标记:Jquery 对asp.net dropdownlist控件更改进行计算,jquery,asp.net,html-select,Jquery,Asp.net,Html Select,我有这个html标记: <div class="table"> <div class="col1 right">Start: </div> <div class="col2outer center"> <div class="col2mid"> <asp:DropDownList ID=
<div class="table">
<div class="col1 right">Start:
</div>
<div class="col2outer center">
<div class="col2mid">
<asp:DropDownList ID="ddlStartHour" runat="server" onchange="Calculate();">
<asp:ListItem Value="1">1</asp:ListItem>
<asp:ListItem Value="2">2</asp:ListItem>
<asp:ListItem Value="3">3</asp:ListItem>
<asp:ListItem Value="4">4</asp:ListItem>
</asp:DropDownList>
</div>
<div class="col2side">
<asp:DropDownList ID="ddlStartMinute" runat="server" onchange="calculateTime()">
<asp:ListItem Value="0">0</asp:ListItem>
<asp:ListItem Value="30">30</asp:ListItem>
</asp:DropDownList>
</div>
</div>
</div>
<div class="table">
<div class="col1 right">Finish:
</div>
<div class="col2outer center">
<div class="col2mid">
<asp:DropDownList ID="ddlFinishHour" runat="server" onchange="Calculate();">
<asp:ListItem Value="1">1</asp:ListItem>
<asp:ListItem Value="2">2</asp:ListItem>
<asp:ListItem Value="3">3</asp:ListItem>
<asp:ListItem Value="4">4</asp:ListItem></asp:DropDownList>
</div>
<div class="col2side">
<asp:DropDownList ID="ddlFinishMinute" runat="server" >
<asp:ListItem Value="0">0</asp:ListItem>
<asp:ListItem Value="30">30</asp:ListItem>
</asp:DropDownList>
</div>
</div>
</div>
<div class="margin1">
<h4>total</h4>
<h3><asp:Label ID="Label1" runat="server">0</asp:Literal></h3>
<h4>hrs</h4>
</div>
开始:
)代码,但它不适用于asp.net控件
function Calculate() {
//get values
var valuestart = $("#<%= ddlStartH.ClientID %>").val();
var valuestop = $("#<%= ddlFinishH.ClientID %>").val();
//create date format
var timeStart = new Date("01/01/2007 " + valuestart).getHours();
var timeEnd = new Date("01/01/2007 " + valuestop).getHours();
var hourDiff = timeEnd - timeStart - 0.5;
$('#<%= lblDuration.ClientID %>').val(hourDiff);
}
函数计算(){
//获取价值
var valuestart=$(“#”)val();
var valuestop=$(“#”)val();
//创建日期格式
var timeStart=新日期(“01/01/2007”+valuestart).getHours();
var timeEnd=新日期(“01/01/2007”+valuestop).getHours();
var hourDiff=timeEnd-timeStart-0.5;
$('#').val(hourDiff);
}
感谢您的帮助。请尝试以下操作:
var timeStart = new Date("01/01/2007 " + valuestart + ":00:00").getHours();
var timeEnd = new Date("01/01/2007 " + valuestop + ":00:00").getHours();
而不是:
var timeStart = new Date("01/01/2007 " + valuestart).getHours();
var timeEnd = new Date("01/01/2007 " + valuestop).getHours();
$('#')。文本(hourDiff)代码>?????你不认为它是$('ddlStartHour')
而不是$(“#”)
@ArunPJohny我认为它需要clientID,因为它是一个asp.net控件。不是html元素。@请使用浏览器开发人员工具检查元素的实际id