jQuery 改变文本颜色的插件
jQuery plugin for change color of text
我是 jQuery 的新人,我想制作我的第一个插件。
它应该在悬停时改变颜色,而不是在鼠标按下时改变颜色。
我的代码有错误吗?
见
这个jsfiddle
jQuery
;(function($, window, document, undefined){
$.fn.test = function () {
return this.each(function(){
this.hover(function(){
this.css('color', 'red');
});
});
}
})(jQuery, window, document);
感谢您的帮助。
这是工作代码:
;(function($, window, document, undefined){
$.fn.test = function () {
this.each(function(){
$(this).hover(function(){
$(this).css('color', 'red');
});
});
return this;
};
})(jQuery, window, document);
http://jsfiddle.net/g690fp7a/2/
检查这个 fiddle
$("a").hover(function() {
$(this).css("color", "red");
});
$("a").mouseout(function() {
$(this).css("color", "blue");
});
你可以用这个。
$(document).ready(function(){
$("a").hover(function(){
$(this).css("background-color", "black");
}, function(){
$(this).css("background-color", "transparent");
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<body>
<a href="#">blabla</a>
<a href="#">blabla</a>
<a href="#">blabla</a>
<a href="#">blabla</a>
</body>
我是 jQuery 的新人,我想制作我的第一个插件。 它应该在悬停时改变颜色,而不是在鼠标按下时改变颜色。
我的代码有错误吗?
见
这个jsfiddle
jQuery
;(function($, window, document, undefined){
$.fn.test = function () {
return this.each(function(){
this.hover(function(){
this.css('color', 'red');
});
});
}
})(jQuery, window, document);
感谢您的帮助。
这是工作代码:
;(function($, window, document, undefined){
$.fn.test = function () {
this.each(function(){
$(this).hover(function(){
$(this).css('color', 'red');
});
});
return this;
};
})(jQuery, window, document);
http://jsfiddle.net/g690fp7a/2/ 检查这个 fiddle
$("a").hover(function() {
$(this).css("color", "red");
});
$("a").mouseout(function() {
$(this).css("color", "blue");
});
你可以用这个。
$(document).ready(function(){
$("a").hover(function(){
$(this).css("background-color", "black");
}, function(){
$(this).css("background-color", "transparent");
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<body>
<a href="#">blabla</a>
<a href="#">blabla</a>
<a href="#">blabla</a>
<a href="#">blabla</a>
</body>