我在员工申请休假时正在执行某项功能,他们必须选择 Start_Date 和 End_Date ,下面有1个标签会显示申请了多少天,我做的是当 End_Date 是onchange时会调用一个JavaScript函数并使用ajax提交,计算和ajax提交工作正常,但问题是我无法得到天数并分配给标签。 这是我的代码:
<div class="form-group">
<label class="col-sm-3 control-label">Start Date <span class="required"> *</span></label>
<div class="col-md-5 col-sm-5 col-xs-12">
<input type="text" class="form-control datepicker" id="start_date" name="start_date" placeholder="yyyy-mm-dd" value="">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">End Date <span class="required"> *</span></label>
<div class="col-md-5 col-sm-5 col-xs-12">
<input type="text" class="form-control datepicker" id="end_date" name="end_date" onchange="getWorkingDays()" placeholder="yyyy-mm-dd" value="">
</div>
</div>
<div class="form-group">
<label for="field-1" class="col-sm-3 control-label">Leave Requested</label>
<div class="col-md-5 col-sm-5 col-xs-12">
<label for="field-1" class="control-label" id="days"></label>
</div>
</div>
的JavaScript
function getWorkingDays() {
var start_date = $('#start_date').val();
var end_date = $('#end_date').val();
var data = "action=countLeaveDays&start_date=" + start_date + "&end_date=" + end_date;
$.ajax({
url: "apply_leave_application.php",
type: "POST",
data: data,
success: function(xml) {
alert(xml);
$(xml).find('item').each(function() {
alert(123);
var label = $(this).text();
$("#days").val(label);
});
}
});
}
当我提醒XML
时<!DOCTYPE html><html lang="en">
<head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="../asset/css/main.css" rel="stylesheet">
<link href="../asset/css/guardian.css" rel="stylesheet"> <!-- Date and Time Picker CSS -->
<link href="../asset/css/datepicker.css" rel="stylesheet" type="text/css" /> <!-- All Icon CSS -->
<link rel="stylesheet" href="../asset/fonts/entypo/css/entypo.css" >
<link rel="stylesheet" href="../asset/fonts/css/font-awesome.min.css" >
<link href='http://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'><!-- Data Table CSS -->
<link href="../asset/css/metisMenu/metisMenu.min.css" rel="stylesheet" type="text/css" /> <link href="../asset/css/datatables/css/dataTables.bootstrap.css" rel="stylesheet" type="text/css" />
<link href="../asset/css/select2.css" rel="stylesheet" type="text/css"/> <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries --><!-- WARNING: Respond.js doesn't work if you view the page via file:// --><!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></scri..."">
<a href="employee/dashboard/inbox">Inbox</a></li>
<li class=""><a href="employee/dashboard/sent">Sent</a></li></ul></li>
<li class=""><a href="leave_application.php">Leave Application</a></li>
<li class=""><a href="all_notice.php">Notice</a></li>
<li class=""><a href="all_holidays.php">Holidays</a></li></ul>
<ul class="main-menu nav navbar-nav navbar-right">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown"><i class="fa fa-user"></i> Profile<b class="caret"></b></a>
<ul class="dropdown-menu">
<li class=""><a href="employee/dashboard/change_password">Change Password</a></li>
<li><a href="logout.php">Logout</a></li></div><!-- /.navbar-collapse --></nav></div></nav></div></div></header></div>
<item>2</item>
<item>2</item>
这只是我想要的,我已经尝试了
$(xml).find('item').each(function() {
alert(123);
var label = $(this).text();
$("#days").val(label);
});
没有回复