如何在onclick 没有 jQuery的情况下制作,没有HTML中的额外代码,例如:
<a href="#" onclick="tramtramtram">
Run Code Online (Sandbox Code Playgroud)
只是使用外部js文件?
<script type="text/javascript" src="functions.js"></script>
Run Code Online (Sandbox Code Playgroud)
我需要替换这段代码:
$("a.scroll-up, a.scroll-down").click(function(){
SNavigate($(this).attr("href").substr(7));return false;
});
Run Code Online (Sandbox Code Playgroud) 使用颜色插件在悬停时为背景颜色设置动画.
$(function() {
$('.listing-2 li a').mouseover(function() {
$(this).animate({
backgroundColor: "#0e7796"
}, 'fast');
});
$('.listing-2 li a').mouseout(function() {
$(this).animate({
backgroundColor: "#d6f2c5"
}, 'fast');
});
});
Run Code Online (Sandbox Code Playgroud)
如何为边框颜色做同样的事情?
我有一个这样的jQuery函数:
$("input").focus(function () {
$(this).addClass('focus');
});
$("input").blur(function () {
$(this).removeClass('focus');
});
$("select").focus(function () {
$(this).addClass('focus');
});
$("select").blur(function () {
$(this).removeClass('focus');
});
$("textarea").focus(function () {
$(this).addClass('focus');
});
$("textarea").blur(function () {
$(this).removeClass('focus');
});
Run Code Online (Sandbox Code Playgroud)
是否可以优化,减少代码?
我们公司的博客有 3 位作者,每个作者在个人资料设置中都有自己的网站网址:
Mike - http://mike.com
Gelens - http://gelens.com
Admin - http://site.com/company/
Run Code Online (Sandbox Code Playgroud)
个人资料的链接是:
http://site.com/author/Mike/
http://site.com/author/Gelens/
http://site.com/author/Admin/
Run Code Online (Sandbox Code Playgroud)
我需要替换一个到管理员页面的链接,所以,如果<?php the_author_posts_link(); ?>某个页面上有标签,并且作者是管理员,那么链接必须是http://site.com/company/而不是http://site.com/author/Admin/.
我怎样才能做到这一点?
1套:
$('#tabs li:first-child').addClass('first-child');
$('.photos li:first-child').addClass('first-child');
$('#alphabet li:first-child').addClass('first-child');
Run Code Online (Sandbox Code Playgroud)
2套:
$(function(){
$("#header-thumbs img").fadeTo("fast",1);
$("#header-thumbs img").hover(function(){
$(this).fadeTo("fast",.7)},function(){
$(this).fadeTo("fast",1)})});
$(function(){$(".catalog dt img").fadeTo("fast",1);
$(".catalog dt img").hover(function(){
$(this).fadeTo("fast",.7)},function(){
$(this).fadeTo("fast",1)})});
$(function(){$(".photos li img").fadeTo("fast",1);
$(".photos li img").hover(function(){
$(this).fadeTo("fast",.7)},function(){
$(this).fadeTo("fast",1)})});
Run Code Online (Sandbox Code Playgroud)
是否可以优化,减少代码?
感谢Paolo Bergantino的帮助,结果是:
优化和打包第一组(540-> 171):
$(function(){$("#header-thumbs, .catalog dt, .photos li").find("img").fadeTo("fast",1).hover(function(){$(this).fadeTo("fast",.7)},function(){$(this).fadeTo("fast",1)})});
Run Code Online (Sandbox Code Playgroud)
第二组(158-> 78):
$('#tabs, .photos, #alphabet').find('li:first-child').addClass('first-child');
Run Code Online (Sandbox Code Playgroud)
二手Dean Edwards包装工