图片一(正常效果)
图片二
$(function () { var date      = new Date();
var firstDate = new Date(date.getFullYear(), date.getMonth(), 1);
var lastDate  = new Date(date.getFullYear(), date.getMonth() + 1, 0);
$("#result").append("firstDate getDay= " + firstDate.getDay() +" <br/>");
$("#result").append("lastDate getDate= " + lastDate.getDate() +" <br/>");
$("#result").append("Date getMonth= " + (date.getMonth()+1) +" <br/>"); // 设置年月
$('h2').text(date.getFullYear() + '/' + (date.getMonth() + 1)); // 设置星期
var week = ['日', '一', '二', '三', '四', '五', '六'];
$.each(week, function(index, value) {
if (index == 0) {
$('<li/>').text(value).css('backgroundColor', '#f00').appendTo('ul');
} else {
$('<li/>').text(value).appendTo('ul');
}
}); // 设置日期
var calendarNum = (firstDate.getDay() + lastDate.getDate()) <= 35 ? 7 * 5 : 7 * 6;
var day = 0;
$.each((new Array(calendarNum)), function(index, value) {
var dayValue = '';
if (index >= firstDate.getDay() && day < lastDate.getDate()) {
day++;
dayValue = (date.getMonth() + 1) + '/' + day;
}
var myday = new Date(date.getFullYear(), date.getMonth(), day);
$("#result").append(myday.toString()+" getDay= " + myday.getDay() + "<br/>");
if ((new Date(date.getFullYear(), date.getMonth(), day).getDay()) == 0 && dayValue != '') {
$('<li/>').text(dayValue).css('backgroundColor', '#f00').appendTo('ul');
} else {
$('<li/>').text(dayValue).appendTo('ul');
}
}); // 指定多个选择设置
$('ul').selectable({
filter: 'li:contains(' + (date.getMonth() + 1) + '/)',
stop: function() {
var result = $('#result').empty();
$('.ui-selected', this).each(function(){
result.append('<' + $(this).text() + '>');
});
}
});
});<body><div id="header">
<h1>元素选择</h1>
<!-- #header --></div><div class="container"><div id="container"><h2></h2>
<ul></ul>
<div id="result"></div><!-- #container --></div><!-- .container --></div><div id="footer">
<!-- #footer --></div></body>问题很简单!!
就是JS文件中的 $('.ui-selected', this).each(function(){ 这句话
问题1:这里的this有意义吗?我删了以后发现其实效果是一样的
问题2:这里应该是Jquery获取多个元素,但是如果$(this, '.ui-selected')颠倒写的话,则会出现图片二的效果,相当于失去了选择CSS的效果了
问题比较小,但是想不明白所以比较纠结,请各位大大帮忙解决一下,谢谢!!