js未分类

时间:2023-03-09 01:25:37
js未分类
jQuery设置透明
1.直接.fadeIn 淡入 .fadeOut 淡出
.fadeTo(时间,"透明度") 2.addClass只能控制淡入和淡出,不能控制其速度。
filter:alpha(Opacity=80);-moz-opacity:0.5;opacity: 0.5;要考滤兼容样式 3.用animate()来完,不用考虑样式兼容问题。
$("#testID").mouseover(function(){
$(this).animate({'opacity':'0.3%'},800);
}).mouseout(function(){
$(this).animate({'opacity':'1.0%'},800);
}); 4.Jquery实现回车键Enter切换焦点
$('input:text:first').focus(); var $inp = $('input:text'); $inp.bind('keydown', function (e) { var key = e.which; if (key == 13) { e.preventDefault(); var nxtIdx = $inp.index(this) + 1; $(":input:text:eq(" + nxtIdx + ")").focus(); } });
分析: $('input:text:first').focus(); 页面初始化时,焦点定位第一个文本框内 var $inp = $('input:text'); 取的type=文本框的元素集合
$inp.bind('keydown', function (e) {}
给文本框集合绑定'keydown'事件 var key = e.which; 取的当前按下的键值 比如Enter的键值=13 e.preventDefault(); 可以阻止它的默认行为的发生而发生其他的事情,在这里我们组织PostBack发生,而是切换焦点。另外一个相近的方法是stopPropagation,它起到阻止js事件冒泡的作用。 将元素装入数组
var index = [];
$(".slidecount li").each(function () {
index.push($(this).index());
});