- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个我使用 javascript 做的 cookie 并检查它是否必须被替换我在 HTML 的 body 标签中使用了“onload=checkCookie()”,但是现在我试图将 js 放在另一个文件并使用标签链接它,但如果我这样做,我就不能再只使用“onload”调用这个函数,所以我想知道我该怎么做?我问过的其他人都告诉我把代码留在那里,但我想把我的设计分层 =S
这是js:
function getCookie(c_name){
if (document.cookie.length>0){
c_start=document.cookie.indexOf(c_name + "=");
if (c_start!=-1){
c_start=c_start + c_name.length+1;
c_end=document.cookie.indexOf(";",c_start);
if (c_end==-1) c_end=document.cookie.length;
return unescape(document.cookie.substring(c_start,c_end));
}
}
return "";
}
function setCookie(c_name,value,expiredays){
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}
function checkCookie(){
username=getCookie('username');
if(username!=null && username!=""){
alert('Welcome again '+username+'!');
}else{
username=prompt('Please enter your name:',"");
if(username!=null && username!=""){
setCookie('username',username,365);
}
}
}
一切都在一个名为 init.js 的文件中
最佳答案
我不明白这个问题,即使它来自外部文件,你也应该能够使用主体的 onload 来执行 javascript,如下所示:
这是 html:
<html>
<head>
<script type="text/javascript" src="script.js"></script>
</head>
<body onload="hello()">
</body>
</html>
这是链接的javascript:
var hello = function()
{
alert("Hello!");
}
关于Javascript Cookie onload 调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/670384/
所以我想隐藏一个div,所以我有我的代码 function hide(){hide div code} document.onload = hide(); 不起作用。 window.onload =
我有一个外部 js 文件,它有一个函数,该函数旨在在文档正文加载后运行。这是我到目前为止所拥有的,但它并没有像它应该的那样工作。请一些帮助。 外部JS文件 window.document.body.a
我觉得这很有趣。考虑以下代码, window.onload 和 body onload=""调用相同的函数。但是,结果不同。在我看来,window.onload 的集合有问题。这是代码:
我多次在链接上使用 Shadowbox,我知道 href 指示 Shadowbox 像这样在框中加载什么页面: 但是,我现在需要在用户进入页面时立即显示一个阴影框。不是onclick,而是onloa
我正在制作一个页眉和页脚不变的网站。单击站点时,主 div 会更改。这是代码: Item 1 ... $("#item").click(function(){$("#main").load("i
我在网页中有 2 个函数 (js) 用于将图像附加到 Canvas 元素: function attachImage(tile, x, y) { base_image = new
首先向大家问好。我是 jquery 的新手,并且在学习曲线上。 我的脚本是这样的: $(function () { $('#content').find('#nav a').on('click'
我今天遇到了一个奇怪的错误。我有一个简单的用户脚本,它添加了一个 window.onload事件到所有网站。但是其中一个网站有一个 定义。发生的事情是 window.onload像往常一样工作但是安装
今天我遇到了一个奇怪的问题: window.onload 在引用名为 onload 的函数时似乎不会触发。 我以前从未注意到这一点: 测试 1: window.onload=onload; funct
假设你想用 JS 把一个元素变成蓝色,像这样: Boy, I sure do wish I was blue 上面的行不起作用,因为 this 以该上下文中的 window 对象为目标。您可以使用 I
我的问题与此处提出的问题类似,但又略有不同,window.onload vs 那道题是用 window.onload 和内联 js 的对比。 我的问题是下面的区别。假设正文标签的 ID 为“body
window.onload事件和body标签的onload事件到底有什么区别?我什么时候使用哪个以及如何正确使用? 最佳答案 window.onload = myOnloadFunc和 是使用同一事件
哪个得到更广泛的支持:window.onload 或 document.onload? 最佳答案 他们什么时候开火? window.onload 默认情况下,它会在整个页面加载时触发,包括其内容(图像
之间有什么区别: window.onload = someFunction; window.onload = someFunction(); 括号在最后。它们有什么不同吗? 我们一般使用第一个!如果我
在 this question 的答案中,我们读到 function f() {}在本地定义名称,而 [var] f = function() {}全局定义它。这对我来说很有意义,但是这两个声明之间存
当我将索引值传递给 onLoad() 时,因此当它开始在后台运行时,它将使用索引值来索引数组。问题是,从表面上看,当 onLoad() 开始运行时,它引用的索引值始终是最后一个索引。 我尝试将每个请求
假设我有这个页面: Hello, world! test.html 包含以下内容: huge.png由于某种原因是100mb。 我无法控制 test.html,但我必须在我的页面中包含 ifram
我正在做以下工作。如果启用了 js,它基本上会通过 ?answer=1。在我添加 onload 参数之前它一直有效(因为我希望这在没有用户触发的情况下发生)。但是,添加 onload 似乎会停止(否则
我可以同时使用body onload和window.onload吗?我已经使用此代码尝试过 window.onload = alertSec; 但是没有成功。我只是需要有人向我确认一下
我可以同时使用body onload和window.onload吗?我已经使用此代码尝试过 window.onload = alertSec; 但是没有成功。我只是需要有人向我确认一下
我是一名优秀的程序员,十分优秀!