将 jquery 代码设置为正文页面加载
Set jquery code to body page onload
嗨,伙计们,我有这个jquery代码,我在网上搜索了它。 我是 jquery 的新手。 代码需要单击按钮才能执行。 我的问题是如何在页面加载时执行此 jQuery 的代码。
<button id="notification-trigger" class="progress-button">
<span class="content">Show Notification</span>
<span class="progress"></span>
</button>
<script>
(function() {
var bttn = document.getElementById( 'notification-trigger' );
// make sure..
bttn.disabled = false;
bttn.addEventListener( 'click', function() {
// simulate loading (for demo purposes only)
classie.add( bttn, 'active' );
setTimeout( function() {
classie.remove( bttn, 'active' );
// create the notification
var notification = new NotificationFx({
message : '<div class="ns-thumb"><img src="img/user1.jpg"/></div><div class="ns-content"><p>Welcome, Nixxx!</p></div>',
layout : 'other',
ttl : 6000,
effect : 'thumbslider',
type : 'notice', // notice, warning, error or success
onClose : function() {
bttn.disabled = false;
}
});
// show the notification
notification.show();
}, 1200 );
// disable the button (for demo purposes only)
this.disabled = true;
} );
})();
</script>
我想要这样的东西:
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
</head>
<body onload="myFunction()">
<h1>Hello World!</h1>
<script>
function myFunction() {
$("#div1").fadeToggle();
$("#div2").fadeToggle("slow");
$("#div3").fadeToggle(3000);
}
</script>
</body>
</html>
请帮忙谢谢!
(已编辑,我包括在脚本执行之前需要单击的按钮。 我希望每次加载/刷新页面时执行此代码,而不是通过单击按钮。 感谢您的帮助!
请使用以下代码。它的工作方式与Vanilla Javascript的onload((函数相同。
<script>
// $(function(){}); Wrapper acts as the document.ready of vanilla javascript
$(function(){
//call myfunction() onload;
myFunction();
//functions to execute goes in here
function myFunction() {
$("#div1").fadeToggle();
$("#div2").fadeToggle("slow");
$("#div3").fadeToggle(3000);
//call button action instead of click
btnFunction();
}
var bttn = document.getElementById( 'notification-trigger' );
bttn.disabled = false;
function btnFunction() {
classie.add( bttn, 'active' );
setTimeout( function() {
classie.remove( bttn, 'active' );
var notification = new NotificationFx({
message : '<div class="ns-thumb"><img src="img/user1.jpg"/></div><div class="ns-content"> <p>Welcome, Nikko Zabala!</p></div>',
layout : 'other',
ttl : 6000,
effect : 'thumbslider',
type : 'notice', // notice, warning, error or success
onClose : function() {
bttn.disabled = false;
}
});
notification.show();
}, 1200 );
};
});
</script>
使用 :
<script>
$(document).ready(function(){
myFunction()
// put your code here;
});
function myFunction() {
// your code
}
function btnFunction(){
// your code
}
</script>
相关文章:
- 返回上一页,不加载执行正文
- 正在将图像加载到文档中.正文背景
- 如何在正文加载之前使用 javascript 滚动页面
- 正文加载创建空白页
- 如何在 ADF 中的 JSF 片段加载(如正文加载)时调用 javascript 函数
- 页面加载后向<正文>添加元素时出现问题
- html中是否有诸如“先加载标头,最后加载正文”之类的东西
- 在图像单击时更改正文加载
- 我只想在 Iframe 中加载(实时)源 url 的正文
- 在页面加载后在 html 正文中注入外部 JavaScript 文件
- 将 jquery 代码设置为正文页面加载
- HTML 正文加载函数需要删除并使用 cookie 执行相同的函数,但只能进行第一次访问
- Javascript正文加载一次
- 如何维护HTML头部/正文块加载到流星应用程序的顺序
- 在正文中异步加载的JS使浏览器处于“加载”模式
- 如何将此 Jquery 代码设置为正文加载
- 科尔多瓦 - 首先检查互联网连接,然后加载正文页面
- $(document).ready()是否在加载正文中的所有脚本文件后调用
- 如何在页面加载后(加载所有站点图像后)完全加载正文背景图像
- 在加载正文时向用户发送屏幕分辨率的Javascript