当前位置:首页 > 代码 > 正文

公告js代码(网站公告代码)

admin 发布:2022-12-19 21:19 116


今天给各位分享公告js代码的知识,其中也会对网站公告代码进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

求js这段代码

////////////////////////////////////////////////guang gao

document.writeln("script language=Jscript");

document.writeln("!--");

document.writeln("var x0=0,y0=0,x1=0,y1=0;");

document.writeln("var offx=6,offy=6;");

document.writeln("var moveable=false;");

document.writeln("var hover=\'red\',normal=\'slategray\';\/\/color;");

document.writeln("var index=10000;\/\/z-index;");

document.writeln("\/\/开始拖动;");

document.writeln("function startDrag(obj)");

document.writeln("{");

document.writeln(" if(event.button==1)");

document.writeln(" {");

document.writeln(" \/\/锁定标题栏;");

document.writeln(" obj.setCapture();");

document.writeln(" \/\/定义对象;");

document.writeln(" var win = obj.parentNode;");

document.writeln(" var sha = win.nextSibling;");

document.writeln(" \/\/记录鼠标和层位置;");

document.writeln(" x0 = event.clientX;");

document.writeln(" y0 = event.clientY;");

document.writeln(" x1 = parseInt(win.style.left);");

document.writeln(" y1 = parseInt(win.style.top);");

document.writeln(" \/\/记录颜色;");

document.writeln(" normal = obj.style.backgroundColor;");

document.writeln(" \/\/改变风格;");

document.writeln(" obj.style.backgroundColor = hover;");

document.writeln(" win.style.borderColor = hover;");

document.writeln(" obj.nextSibling.style.color = hover;");

document.writeln(" sha.style.left = x1 + offx;");

document.writeln(" sha.style.top = y1 + offy;");

document.writeln(" moveable = true;");

document.writeln(" }");

document.writeln("}");

document.writeln("\/\/拖动;");

document.writeln("function drag(obj)");

document.writeln("{");

document.writeln(" if(moveable)");

document.writeln(" {");

document.writeln(" var win = obj.parentNode;");

document.writeln(" var sha = win.nextSibling;");

document.writeln(" win.style.left = x1 + event.clientX - x0;");

document.writeln(" win.style.top = y1 + event.clientY - y0;");

document.writeln(" sha.style.left = parseInt(win.style.left) + offx;");

document.writeln(" sha.style.top = parseInt(win.style.top) + offy;");

document.writeln(" }");

document.writeln("}");

document.writeln("\/\/停止拖动;");

document.writeln("function stopDrag(obj)");

document.writeln("{");

document.writeln(" if(moveable)");

document.writeln(" {");

document.writeln(" var win = obj.parentNode;");

document.writeln(" var sha = win.nextSibling;");

document.writeln(" var msg = obj.nextSibling;");

document.writeln(" win.style.borderColor = normal;");

document.writeln(" obj.style.backgroundColor = normal;");

document.writeln(" msg.style.color = normal;");

document.writeln(" sha.style.left = obj.parentNode.style.left;");

document.writeln(" sha.style.top = obj.parentNode.style.top;");

document.writeln(" obj.releaseCapture();");

document.writeln(" moveable = false;");

document.writeln(" }");

document.writeln("}");

document.writeln("\/\/获得焦点;");

document.writeln("function getFocus(obj)");

document.writeln("{");

document.writeln(" if(obj.style.zIndex!=index)");

document.writeln(" {");

document.writeln(" index = index + 2;");

document.writeln(" var idx = index;");

document.writeln(" obj.style.zIndex=idx;");

document.writeln(" obj.nextSibling.style.zIndex=idx-1;");

document.writeln(" }");

document.writeln("}");

document.writeln("\/\/最小化;");

document.writeln("function min(obj)");

document.writeln("{");

document.writeln(" var win = obj.parentNode.parentNode;");

document.writeln(" var sha = win.nextSibling;");

document.writeln(" var tit = obj.parentNode;");

document.writeln(" var msg = tit.nextSibling;");

document.writeln(" var flg = msg.style.display==\"none\";");

document.writeln(" if(flg)");

document.writeln(" {");

document.writeln(" win.style.height = parseInt(msg.style.height) + parseInt(tit.style.height) + 2*2;");

document.writeln(" sha.style.height = win.style.height;");

document.writeln(" msg.style.display = \"block\";");

document.writeln(" obj.innerHTML = \"0\";");

document.writeln(" }");

document.writeln(" else");

document.writeln(" {");

document.writeln(" win.style.height = parseInt(tit.style.height) + 2*2;");

document.writeln(" sha.style.height = win.style.height;");

document.writeln(" obj.innerHTML = \"2\";");

document.writeln(" msg.style.display = \"none\";");

document.writeln(" }");

document.writeln("}");

document.writeln("\/\/关闭;");

document.writeln("function cls(obj)");

document.writeln("{");

document.writeln(" var win = obj.parentNode.parentNode;");

document.writeln(" var sha = win.nextSibling;");

document.writeln(" win.style.visibility = \"hidden\";");

document.writeln(" sha.style.visibility = \"hidden\";");

document.writeln("}");

document.writeln("\/\/创建一个对象;");

document.writeln("function xWin(id,w,h,l,t,tit,msg)");

document.writeln("{");

document.writeln(" index = index+2;");

document.writeln(" this.id = id;");

document.writeln(" this.width = w;");

document.writeln(" this.height = h;");

document.writeln(" this.left = l;");

document.writeln(" this.top = t;");

document.writeln(" this.zIndex = index;");

document.writeln(" this.title = tit;");

document.writeln(" this.message = msg;");

document.writeln(" this.obj = null;");

document.writeln(" this.bulid = bulid;");

document.writeln(" this.bulid();");

document.writeln("}");

document.writeln("\/\/初始化;");

document.writeln("function bulid()");

document.writeln("{");

document.writeln(" var str = \"\"");

document.writeln(" + \"div id=xMsg\" + this.id + \" \"");

document.writeln(" + \"style=\'\"");

document.writeln(" + \"z-index:\" + this.zIndex + \";\"");

document.writeln(" + \"width:\" + this.width + \";\"");

document.writeln(" + \"height:\" + this.height + \";\"");

document.writeln(" + \"left:\" + this.left + \";\"");

document.writeln(" + \"top:\" + this.top + \";\"");

document.writeln(" + \"background-color:\" + normal + \";\"");

document.writeln(" + \"color:\" + normal + \";\"");

document.writeln(" + \"font-size:12px;\"");

document.writeln(" + \"font-family:Verdana;\"");

document.writeln(" + \"position:absolute;\"");

document.writeln(" + \"cursor:default;\"");

document.writeln(" + \"border:2px solid \" + normal + \";\"");

document.writeln(" + \"\' \"");

document.writeln(" + \"onmousedown=\'getFocus(this)\'\"");

document.writeln(" + \"div \"");

document.writeln(" + \"style=\'\"");

document.writeln(" + \"background-color:\" + normal + \";\"");

document.writeln(" + \"width:\" + (this.width-2*2) + \";\"");

document.writeln(" + \"height:20;\"");

document.writeln(" + \"color:#ebf1ff;\"");

document.writeln(" + \"\' \"");

document.writeln(" + \"onmousedown=\'startDrag(this)\' \"");

document.writeln(" + \"onmouseup=\'stopDrag(this)\' \"");

document.writeln(" + \"onmousemove=\'drag(this)\' \"");

document.writeln(" + \"ondblclick=\'min(this.childNodes[1])\'\"");

document.writeln(" + \"\"");

document.writeln(" + \"span style=\'width:\" + (this.width-2*12-4) + \";padding-left:3px;\'\" + this.title + \"\/span\"");

document.writeln(" + \"span style=\'width:12;border-width:0px;color:#ebf1ff;font-family:webdings;\' onclick=\'min(this)\'0\/span\"");

document.writeln(" + \"span style=\'width:12;border-width:0px;color:#ebf1ff;font-family:webdings;\' onclick=\'cls(this)\'r\/span\"");

document.writeln(" + \"\/div\"");

document.writeln(" + \"div style=\'\"");

document.writeln(" + \"width:100%;\"");

document.writeln(" + \"height:\" + (this.height-20-4) + \";\"");

document.writeln(" + \"background-color:#ebf1ff;\"");

document.writeln(" + \"line-height:16px;\"");

document.writeln(" + \"word-break:break-all;\"");

document.writeln(" + \"padding:3px;\"");

document.writeln(" + \"\'\" + this.message + \"\/div\"");

document.writeln(" + \"\/div\"");

document.writeln(" + \"div style=\'\"");

document.writeln(" + \"width:\" + this.width + \";\"");

document.writeln(" + \"height:\" + this.height + \";\"");

document.writeln(" + \"top:\" + this.top + \";\"");

document.writeln(" + \"left:\" + this.left + \";\"");

document.writeln(" + \"z-index:\" + (this.zIndex-1) + \";\"");

document.writeln(" + \"position:absolute;\"");

document.writeln(" + \"background-color:black;\"");

document.writeln(" + \"filter:alpha(opacity=40);\"");

document.writeln(" + \"\'by wildwind\/div\";");

document.writeln(" document.body.insertAdjacentHTML(\"beforeEnd\",str);");

document.writeln("}");

document.writeln("\/\/--");

document.writeln("\/script");

document.writeln("script language=\'Jscript\'");

document.writeln("!--");

document.writeln("function initialize()");

document.writeln("{");

document.writeln(" var b = new xWin(\"2\",250,200,545,200,\"公告\",\"a href=http:\/\/\/E%20pan/yuyi888\/jian%20jie.html target=_blank业务简介\/abra href=http:\/\/\/E%20pan\/index.html target=_blank特效代码\/abr热烈庆祝本站2008年9月6日再次被百度收录(关键词:E盘天王)brbr本站7月31晚新推出E盘功能区特效(功能区可隐藏,只要点下特殊开关就可立即显示。让你再也不用到后台修改代码了),有需要的联系我们。欢迎前来定作。br我站营业时间:星期一至星期六(每天晚上9点30分至2点)星期天24小时营业。\");");

document.writeln("}");

document.writeln("window.onload = initialize;");

document.writeln("\/\/--");

document.writeln("\/script")

我做了个滚动公告的js怎么把它用到主页指定位置呢?

终于研究出来了,原来是层的位置没调好。。。这个代码效果不错的,希望大家能用的上层的位置在这段里调整div id="oDiv" style="border-style:solid; border-width:0px; position:absolute;left:0;top:0;width:200;height:120;filter:progidXImageTransform.Microsoft.Slide(slideStyle='PUSH',bands=1); right:0; bottom:0"顺便演示一下 查看原帖

css如何让公告得第一条信息变红色(公告是动态的) 或者css+js

需要在程序输出公告的时候,进行判断,第一条加上一个css类,或者直接设置颜色。

弹出小窗体式公告栏代码

【最基本的弹出窗口代码】

SCRIPT LANGUAGE="javascript"

!--

window.open ('page.html')

--

/SCRIPT

因为这是一段javascript代码,所以它们应该放在SCRIPT LANGUAGE ="javascript"标签和/script之间。

!--和--是对一些版本低的浏览器起作用,在这些老浏览器中如果不支持javascript,不会将标签中的代码作

为文本显示出来。

Window.open ('page.html')用于控制弹出新的窗口page.html,如果page.html不与主窗口在同一路径下,前面

应写明路径,绝对路径(http://)和相对路径(../)均可。

用单引号和双引号都可以,只是不要混用。

这一段代码可以加入HTML的任意位置,加入到head和/head之间也可以,位置越靠前执行越早,尤其是页面

代码较长时,又想使页面早点弹出就尽量往前放。

【经过设置后的弹出窗口】

下面再说一说弹出窗口外观的设置。只要再往上面的代码中加一点东西就可以了。

我们来定制这个弹出窗口的外观、尺寸大小、弹出位置以适应该页面的具体情况。

SCRIPT LANGUAGE="javascript"

!--

window.open('page.html','newwindow','height=100,width=400,top=0,left=0,toolbar=no,menubar=no,scrollbars=no, resizable=no,location=no,status=no')

//写成一行

--

/SCRIPT

参数解释:

SCRIPT LANGUAGE="java script" js脚本开始;

window.open 弹出新窗口的命令;

page.html 弹出新窗口的文件名;

newwindow 弹出窗口的名字(不是文件名),可用空 〃代替;

height=100 窗口高度;

top=0 窗口距离屏幕上方的像素值;

left=0 窗口距离屏幕左侧的像素值;

toolbar=no 是否显示工具栏,yes为显示;

menubar,scrollbars 表示菜单栏和滚动栏;

resizable=no 是否允许改变窗口大小,yes为允许;

location=no 是否显示地址栏,yes为允许;

status=no 是否显示状态栏内的信息(通常是文件已经打开),yes为允许;

/SCRIPT js脚本结束。

【用函数控制弹出窗口】

下面是一个完整的代码。

html

head

script LANGUAGE="javascript"

!--

function openwin(){

window.open("page.html","newwindow","height=100,width=400,toolbar=no,menubar=no,scrollbars=no, resizable=no,location=no,status=no";)

//写成一行

}

--

/script

/head

body onload="openwin()"

...任意的页面内容...

/body

/html

这里定义了一个函数openwin(),函数内容就是打开一个窗口。在调用它之前没有任何用途。怎么调用呢?

方法一:body onload="openwen()" 浏览器读页面时弹出窗口;

方法二:body onunload="openwen()" 浏览器离开页面时弹出窗口;

方法三:用一个连接调用:a href="#" onclick="openwin()"打开一个窗口/a

注意:使用的"#"是虚连接。

方法四:用一个按钮调用:input type="button" onclick="openwin()" value="打开窗口"

【主窗口打开文件1.htm,同时弹出小窗口page.html】

将如下代码加入主窗口head区:

script language="javascript"

!--

function openwin(){

window.open("page.html","","width=200,height=200";)

}

//--

/script

加入body区:a href="1.htm" onclick="openwin()"open/a即可。

【弹出的窗口之定时关闭控制】

下面我们再对弹出窗口进行一些控制,效果就更好了。如果我们再将一小段代码加入弹出的页面(注意是加入到page.html的HTML中,可不是主页面中,否则…),让它在10秒钟后自动关闭是不是更酷了?

首先,将如下代码加入page.html文件的head区:

script language="javascript"

function closeit() {

setTimeout("self.close()",10000) //毫秒

}

/script

然后,再用body onload="closeit()"这一句话代替page.html中原有的BODY这一句就可以了。(这一句话千

万不要忘记写啊!这一句的作用是调用关闭窗口的代码,10秒钟后就自行关闭该窗口。)

【在弹出窗口中加上一个关闭按钮】

form

INPUT TYPE='BUTTON' value='关闭' onClick='window.close()'

/form

呵呵,现在更加完美了!

【内包含的弹出窗口——一个页面两个窗口】

上面的例子都包含两个窗口,一个是主窗口,另一个是弹出的小窗口。

通过下面的例子,你可以在一个页面内完成上面的效果。

html

head

SCRIPT LANGUAGE="javascript"

function openwin()

{

OpenWindow=window.open("","newwin","height=250,width=250,toolbar=no,scrollbars="+scroll+",menubar=no";);

//写成一行

OpenWindow.document.write("TITLE例子/TITLE";)

OpenWindow.document.write("BODY BGCOLOR=#FFFFFF";)

OpenWindow.document.write("H1Hello!/h1";)

OpenWindow.document.write("New window opened!";)

OpenWindow.document.write("/BODY ";)

OpenWindow.document.write("/HTML";)

OpenWindow.document.close()

}

/script

/head

body

a href="#" onclick="openwin()"打开一个窗口/a

input type="button" onclick="openwin()" value="打开窗口"

/body

/html

看看OpenWindow.document.write()里面的代码不就是标准的HTML吗?只要按照格式写更多的行即可。千万注意多一个标签或少一个标签都会出现错误。记住用OpenWindow.document.close()结束啊。

【终极应用——弹出窗口的Cookie控制】

回想一下,上面的弹出窗口虽然酷,但是有一点小毛病(你沉浸在喜悦之中,一定没有发现吧?)比如你将上面的脚本放在一个需要频繁经过的页面里(例如首页),那么每次刷新这个页面,窗口都会弹出一次,是不是非常烦人?有解决的办法吗?Yes!Follow me。我们使用Cookie来控制一下就可以了。

首先,将如下代码加入主页面HTML的HEAD区:

script

function openwin(){

window.open("page.html","","width=200,height=200" ;)

}

function get_cookie(Name){

var search = Name+ "="

var returnvalue ="";

if (documents.cookie.length 0){

offset = documents.cookie.indexOf(search)

if (offset!=-1){

offset += search.length

end = documents.cookie.indexOf (";",offset);

if (end ==-1)

end = documents.cookie.length;

returnvalue =unescape(documents.cookie.substring(offset,end))

}

}

return returnvalue;

}

function loadpopup(){

if (get_cookie(’popped’)==";){

openwin()

documents.cookie="popped=yes"

}

}

/script

然后,用body onload="loadpopup()"(注意不是openwin 而是loadpop啊)替换主页面中原有的BODY这一句即可。你可以试着刷新一下这个页面或重新进入该页面,窗口再也不会弹出了。真正的Pop-Only-Once!

写到这里,弹出窗口的制作和应用技巧基本上算是讲完了,希望对正在制作网页的朋友有所帮助我就非常欣慰了。

需要注意的是,JS脚本中的大小写最好前后保持一致。

没有菜单、工具栏、地址栏的弹出窗口:

script language="javascript"

!--

var gt = unescape('%3e');

var popup = null;

var over = "Launch Pop-up Navigator";

popup = window.open('', 'popupnav', 'width=500,height=500,resizable=0,scrollbars=auto'); // width=500,height=500为窗口长和宽

if (popup != null) {

if (popup.opener == null) {

popup.opener = self; }

popup.location.href = '要打开的文件名';

}

// --

/script

离开一个页面时弹出一个可定制的窗口

!-- Begin

function leave() {

window.open(\'离开页面时弹出窗口的URL\',\'\',\'toolbar=no,menubar=no,location=no,height=235,width=320\');

}

// End --

/script

如下代码加入HTML的BODY区:body onUnload="leave()"

超级弹窗代码(MYIE也照弹)

script language="javascript"

focusid=setTimeout("focus();window.showModelessDialog(\'\',\'\',\'scroll:1;status:0;help:0;resizable:1;dialogWidth:0px;dialogHeight:0px\')",0000)

/script

script language="javascript"

!--

function clock(){i=i-1

document.title="";#定义标题

if(i0)setTimeout("clock();",1000);

else self.close();}

var i=4#定义多少秒后关

clock();

//--

/script

js源代码 如何定时更换页面文字

body

SCRIPT language=javascript

!--

var timer1;

var i=0;

timer1 = setInterval("myval()",2000);

function myval()

{

i+=1;

if(i3)

{

i=1;

}

var show;

if (i==1)

{show = "hello";}

else if(i==2)

{show="ABC";}

else

{show="EDFEEEW";}

label1.innerText = show;

}

--

/SCRIPT

DIV id=label1 title=hello style="DISPLAY: inline; WIDTH: 70px; HEIGHT: 15px" ms_positioning="FlowLayout"Label/DIV

/body

这段脚本可以每隔2秒钟依次在Label上显示“Hello”,“Bye”,“OK”文字。主要原理就是利用了setInterval函数,该函数的用法如下:

setInterval(expression,msec,[language])

expression-要执行的过程;msec时间间隔;language可选项,为指定的语言。

公告js代码的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于网站公告代码、公告js代码的信息别忘了在本站进行查找喔。

版权说明:如非注明,本站文章均为 AH站长 原创,转载请注明出处和附带本文链接;

本文地址:http://ahzz.com.cn/post/24624.html


取消回复欢迎 发表评论:

分享到

温馨提示

下载成功了么?或者链接失效了?

联系我们反馈

立即下载