$(window).bind("load", function() {
$("#placeholder .flot-text .xAxis .tickLabel").css('height','90px','important');
});
嗨,我如何在页面加载后立即执行此功能?仅当我刷新页面时才调用此函数,但我希望在加载页面时调用它。
像这样使用document.ready
$(document).ready(function(){
$("#placeholder .flot-text .xAxis .tickLabel").css('height','90px','important');
});
或者您可以使用$(function)之类的
$(function(){
$("#placeholder .flot-text .xAxis .tickLabel").css('height','90px','important');
});
$(document).ready(function(){
//execute ur code here.
});
试试下面的代码
$(document).ready(function() {
// Handler for .ready() called.
$("#placeholder .flot-text .xAxis .tickLabel").css('height','90px','important');
});
$(function() {
// Handler for .ready() called.
$("#placeholder .flot-text .xAxis .tickLabel").css('height','90px','important');
});
.ready() - 指定在 DOM 完全加载时执行的函数。
使用你可以使用的 jQuery;
$(function(){
//Your code here
});
$(document).ready(function(){
//Write your code
});
将脚本放在底部
脚本引起的问题是它们会阻止并行下载。HTTP/1.1 规范建议浏览器每个主机名并行下载不超过两个组件。如果您从多个主机名提供图像,则可以同时进行两次以上的下载。但是,在下载脚本时,浏览器不会启动任何其他下载,即使在不同的主机名上也是如此。在某些情况下,将脚本移到底部并不容易。例如,如果脚本使用 document.write 插入部分页面内容,则不能将其移至页面下方。也可能存在范围问题。在许多情况下,有一些方法可以解决这些情况。经常出现的另一种建议是使用延迟脚本。DEFER 属性表示该脚本不包含 document.write,并且是浏览器可以继续呈现的线索。不幸的是,Firefox 不支持 DEFER 属性。在 Internet Explorer 中,脚本可能会被延迟,但不会像期望的那样延迟。如果可以推迟脚本,也可以将其移至页面底部。这将使您的网页加载速度更快。