我有这个HTML代码。
<form class="" role="form">
<div class="col-lg-2">
<div class="form-group">
<label for="streams">Select Stream</label>
<select name="streams" id="streams" class="form-control">
<option value="">-- Select --</option>
<?php
while($streamRow = mysql_fetch_array($streamResult)) {
echo
"<option value=".$streamRow[0].">".$streamRow[1]."</option>";
}
?>
</select>
</div>
</div>
<div class="col-lg-2">
<div class="form-group">
<label for="branches">Select Branch</label>
<select name="branches" id="branches" class="form-control">
<option value="">-- Select --</option>
</select>
</div>
</div>
<div class="col-lg-2">
<div class="form-group">
<label for="batches">Select Batch</label>
<select name="batches" id="batches" class="form-control">
<option value="">-- Select --</option>
</select>
</div>
</div>
<div class="col-lg-2">
<div class="form-group divBefore">
<label for="divisionBefore">Div</label>
<select name="divisionBefore" id="divisionBefore" class="form-control">
<option value="">Sel</option>
</select>
</div>
<div class="form-group divAfter hide">
<label for="division">Div</label>
<select name="division" id="division" class="form-control">
<option value="">Sel</option>
<?php
$divisionResult = mysql_query("SELECT * FROM division");
while($divisionRow = mysql_fetch_array($divisionResult)) {
echo
"<option value=".$divisionRow[0].">".$divisionRow[1]."</option>";
}
?>
</select>
</div>
</div>
<div class="col-lg-2">
<div class="form-group semesterBefore">
<label for="semBefore">Sem</label>
<select name="semBefore" id="semBefore" class="form-control">
<option value="">Sel</option>
</select>
</div>
<div class="form-group semesterAfter hide">
<label for="sem">Sem</label>
<select name="sem" id="sem" class="form-control">
<option value="">Sel</option>
</select>
</div>
</div>
<div class="col-lg-2">
<div class="form-group subject">
<label for="subject">Select Subject</label>
<select name="subject" id="subject" class="form-control">
<option value="">-- Select --</option>
</select>
</div>
</div>
<!--<div class="col-lg-2" id="lecBefore">
<div class="form-group">
<label for="subject">Select Lecture</label>
<select name="lect" id="lect" class="form-control">
<option value="">-- Select --</option>
</select>
</div>
</div>
<div class="col-lg-2 hide" id="lecAfter">
<div class="form-group">
<label for="subject">Select Lecture</label>
<select name="lecture" id="lecture" class="form-control">
<option value="">-- Select --</option>
<option value="1">Lecture 1</option>
<option value="2">Lecture 2</option>
<option value="3">Lecture 3</option>
<option value="4">Lecture 4</option>
<option value="5">Lecture 5</option>
<option value="6">Lecture 6</option>
<option value="7">Lecture 7</option>
<option value="8">Lecture 8</option>
</select>
</div>
</div>-->
<div class="col-lg-2 hide" id="date">
<div class="form-group">
<label for="dateNow">Start Date</label> <br>
<div class="input-group date" id="avsDate">
<input type="text" class="form-control" name="avsDateTxt" id="avsDateTxt" readonly value="<?php echo date('d-m-Y');?>"><span class="input-group-addon"><i class="glyphicon glyphicon-th"></i></span>
</div>
</div>
</div>
<div class="col-lg-2 hide" id="date1">
<div class="form-group">
<label for="dateNow">End Date</label> <br>
<div class="input-group date" id="endDate">
<input type="text" class="form-control" name="endDateTxt" id="endDateTxt" readonly value="<?php echo date('d-m-Y');?>"><span class="input-group-addon"><i class="glyphicon glyphicon-th"></i></span>
</div>
</div>
</div>
</form>
我的jquery是。
$(document).ready(function() {
$('.sidebar-menu .attnd').addClass('active');
$('.sidebar-menu .attnd .genExcel').addClass('active');
$(".sidebar-menu .attnd").tree();
$('#streams').change(function() {
$('#branches').html("<option value=''>-- Select --</option>");
$('#batches').html("<option value=''>-- Select --</option>");
$('.divAfter').hide();
$('.divBefore').show();
$('.semesterAfter').hide();
$('.semesterBefore').show();
$('#date').hide();
$('#date1').hide();
$('#lecAfter').hide();
$('#lecBefore').show();
$('#studManip').html('');
if($(this).val() != '')
$.streamSelection($(this).val());
});
$('#branches').change(function() {
$('#batches').html("<option value=''>-- Select --</option>");
$('.divAfter').hide();
$('.divBefore').show();
$('.semesterAfter').hide();
$('.semesterBefore').show();
$('#date').hide();
$('#date1').hide();
$('#lecAfter').hide();
$('#lecBefore').show();
$('#studManip').html('');
if($(this).val() != '')
$.branchSelection($(this).val());
});
$('#batches').change(function() {
$('.divAfter').hide();
$('.divBefore').show();
$('.semesterAfter').hide();
$('.semesterBefore').show();
$('#date').hide();
$('#date1').hide();
$('#lecAfter').hide();
$('#lecBefore').show();
$('#studManip').html('');
if($(this).val() != '') {
$.listSemester($(this).val());
$('.divBefore').hide();
$('#division').val('');
$('.divAfter').show();
}
});
$('#division').change(function() {
$('.studList').hide();
$('.semesterAfter').hide();
$('.semesterBefore').show();
$('#date').hide();
$('#date1').hide();
$('#lecAfter').hide();
$('#lecBefore').show();
$('#studManip').html('');
if($(this).val() != '') {
$('.semesterBefore').hide();
$('#sem').val('');
$('.semesterAfter').show();
}
});
$('#sem').change(function() {
$('#date').hide();
$('#date1').hide();
$('#lecAfter').hide();
$('#lecBefore').show();
$('#studManip').html('');
if($(this).val() != '')
$.searchSubject();
});
$('#subject').change(function() {
if($(this).val() != '') {
$.when($('#date').show())
.then($('#date1').show())
.then($('.btnExcel').show());
}
});
/*$('#lecture').change(function() {
$.when($('#date').hide())
.then($('#studManip').html(''));
if($(this).val() != '') {
$('#date').show();
$.when($.searchStudent())
.then($('#studManip').show());
}
});*/
$('#avsDate').datepicker({
format: "dd-mm-yyyy",
startDate: "01-01-2012",
endDate: '<?php echo date('d-m-Y')?>',
todayBtn: "linked",
autoclose: true,
todayHighlight: true,
});
$('#endDate').datepicker({
format: "dd-mm-yyyy",
startDate: "01-01-2012",
endDate: '<?php echo date('d-m-Y')?>',
todayBtn: "linked",
autoclose: true,
todayHighlight: true,
});
$('#avsDate').datepicker().on('changeDate', function(e) {
$.when($('.btnExcel').attr('href', 'studExcel.php?streamId='+$('#streams').val()+'&branchId='+$('#branches').val()+'&batchId='+$('#batches').val()+'&divisionId='+$('#division').val()+'&semId='+$('#sem').val()+'&sDate='+$('#advDatetxt').val()+'&eDate='+$('#endDatetxt').val()))
.then($('.btnExcel').show());
});
$('#endDate').change(function() {
$.when($('.btnExcel').attr('href', 'studExcel.php?streamId='+$('#streams').val()+'&branchId='+$('#branches').val()+'&batchId='+$('#batches').val()+'&divisionId='+$('#division').val()+'&semId='+$('#sem').val()+'&sDate='+$('#advDatetxt').val()+'&eDate='+$('#endDatetxt').val()))
.then($('.btnExcel').show());
});
/*var date = new Date();
$('#avsDate').datepicker().on('changeDate', function(e) {
$('#studManip').html('');
if(weekday[$(this).datepicker('getDate').getUTCDay()] != 'Sunday'){
$.when($.searchStudent())
.then($('#studManip').show());
} else
alert('Today is Sunday');
});*/
});
$.streamSelection = function(selStreamId) {
$.ajax({
url:"../student/searchBranch.php",
data:{
streamId:selStreamId,
},
success: function(data) {
$('#branches').html(data);
},
error: function(error) {
alert(error);
}
});
}
$.branchSelection = function(selBranchId) {
$.ajax({
url:"../student/searchBatch.php",
data:{
branchId:selBranchId,
},
success: function(data) {
$('#batches').html(data);
},
error: function(error) {
alert(error);
}
});
}
$.listSemester = function(selStreamId) {
$.ajax({
url:"../student/searchStream.php",
data:{
streamId:selStreamId,
},
success: function(data) {
$('#sem').html(data);
},
error: function(error) {
alert(error);
}
});
}
$.searchSubject = function() {
$.ajax({
url:"searchSubject.php",
data:{
streamId : $('#streams').val(),
branchId : $('#branches').val(),
semId : $('#sem').val(),
},
success: function(data) {
$('#subject').html(data);
},
error: function(error) {
alert(error);
}
});
}
每件事都运行正常,但是当我更改 advDatetxt 或 endDatetxt 时,jquery不会使用查询字符串发送值并描述为未定义。当我将光标放在excel按钮上时,它将显示左下角为。
答案 0 :(得分:12)
我认为问题只是拼写错误
<input type="text" class="form-control" name="avsDateTxt" id="avsDateTxt" readonly value="<?php echo date('d-m-Y');?>">
sDate='+$('#advDatetxt').val()
这里拼写id值的错误,将其更改为
sDate='+$('#avsDatetxt').val()
下一个:
<input type="text" class="form-control" name="endDateTxt" id="endDateTxt" readonly value="<?php echo date('d-m-Y');?>">
eDate='+$('#endDatetxt').val()
这里也拼错了,把它换成
eDate='+$('#endDateTxt').val()
答案 1 :(得分:0)
您的部分ID与选择器不匹配。
见这个
id="avsDateTxt"
针对
$('#advDatetxt')