本文目录一览:
有一段非常NB的JS代码
首先不说你理解不理解的问题,这段代码本身就写得很烂……
这种css和结构代码混在一起的形式,让人很不舒服,不过为了简便,我也懒得改了。
我改了一下,帮助你理解
div id="demo" style="overflow: hidden; WIDTH: 70px; height: 50px;border:solid 1px #222222" align="center"
tabletr
td id="demo1" style="border:solid 1px red"
aaaaaabbbcccccc
/td
td id="demo2" style="border:solid 1px green" !-- 新加2个style帮助你理解,删除后你就明白了 --
aaaaaabbb!-- 其实这里根本没必要完全一样,因为这里的后半截是否显示取决于demo的宽度,也就是显示区域 --
/td
/tr/table
/div
SCRIPT language="javascript"
function Marquee(){
if(demo1.offsetWidth-demo.scrollLeft=0) //这里把demo2改成demo1,当demo1完全滚出显示区域时,(转下面)
demo.scrollLeft=0 //让内部滚动条(这里是demo1,demo2)回归原位,造成连续滚动假象
else{
demo.scrollLeft++ //让demo的内部滚动条继续向左滚动1px
}
}
var MyMar=setInterval(Marquee,5)
demo.onmouseover=function() {clearInterval(MyMar)} //当鼠标放在div元素上面时,清除下面的定时执行功能
demo.onmouseout=function() {MyMar=setInterval(Marquee,5)} //每5毫秒执行一次函数,也就是每5秒滚动1px
/SCRIPT
求一段JS代码
按钮驱动文字闪烁
脚本说明:
第一步:把如下代码加入body区域中
SCRIPT LANGUAGE="JavaScript"
var x=9;
var strobe="on"
if (navigator.appName == "Netscape") {
visShow="'show'";
visHide="'hide'";
docStyle="document.";
styleDoc="";
}
else {
visHide="'hidden'";
visShow="'visible'";
docStyle="";
styleDoc=".style";
}
/SCRIPT
SCRIPT LANGUAGE="JavaScript"
function hide1() {
eval(docStyle 'object1' styleDoc '.visibility=' visHide);
}
function hide2() {
eval(docStyle 'object2' styleDoc '.visibility=' visHide);
}
function hide3() {
eval(docStyle 'object3' styleDoc '.visibility=' visHide);
}
function hide4() {
eval(docStyle 'object4' styleDoc '.visibility=' visHide);
}
function hide5() {
eval(docStyle 'object5' styleDoc '.visibility=' visHide);
}
function hide6() {
eval(docStyle 'object6' styleDoc '.visibility=' visHide);
}
function hide7() {
eval(docStyle 'object7' styleDoc '.visibility=' visHide);
}
function hide8() {
eval(docStyle 'object8' styleDoc '.visibility=' visHide);
}
function hide9() {
eval(docStyle 'object9' styleDoc '.visibility=' visHide);
}
function hide10() {
eval(docStyle 'object10' styleDoc '.visibility=' visHide);
}
function show1() {
eval(docStyle 'object1' styleDoc '.visibility=' visShow);
hide2(),hide3();
}
function show2() {
eval(docStyle 'object2' styleDoc '.visibility=' visShow);
hide1(),hide3();
}
function show3() {
eval(docStyle 'object3' styleDoc '.visibility=' visShow);
hide2(),hide4();
}
function show4() {
eval(docStyle 'object4' styleDoc '.visibility=' visShow);
hide3(),hide5();
}
function show5() {
eval(docStyle 'object5' styleDoc '.visibility=' visShow);
hide4(),hide6();
}
function show6() {
eval(docStyle 'object6' styleDoc '.visibility=' visShow);
hide5(),hide7();
}
function show7() {
eval(docStyle 'object7' styleDoc '.visibility=' visShow);
hide6(),hide8();
}
function show8() {
eval(docStyle 'object8' styleDoc '.visibility=' visShow);
hide7(),hide9();
}
function show9() {
eval(docStyle 'object9' styleDoc '.visibility=' visShow);
hide8(),hide10();
}
function show10() {
eval(docStyle 'object10' styleDoc '.visibility=' visShow);
hide9();
}
function strobe1() {
x =1;
eval("show" x "()");
if (x10) setTimeout("strobe1()", 75);
else if (strobe=="on") strobe2();
}
function strobe2() {
x-=1;
eval("show" x "()");
if (x1) setTimeout("strobe2()", 75);
else strobe1();
}
function strobeOn() {
x=9;
strobe="on";
strobe1();
}
function strobeOff() {
strobe="off";
}
/SCRIPT
div id="vis" style="position:absolute; visibility:show; left:175px; top:280px; z-index:1"
table cellpadding=2 border=1tr
tdcenterbStrobe:/b/center/font/a/td
tda href="javascript:strobeOn()"
font color="#000000"centeron/center/font/a/td
tda href="javascript:strobeOff()"
font color="#000000"centeroff/center/font/a/td
/tr/table/div
div id="object1" style="position:absolute; visibility:hide; left:175px; top:300px; z-index:1"
table border=1 bgcolor=#eaffff width=175 height=50tdcenterbfont color="#F9F9F9"JavaScript Planet/font/b/center/td/table
/div
div id="object2" style="position:absolute; visibility:hide; left:175px; top:300px; z-index:1"
table border=1 bgcolor=eaffff width=175 height=50tdcenterbfont color="#ECECEC"JavaScript Planet/font/b/center/td/table
/div
div id="object3" style="position:absolute; visibility:hide; left:175px; top:300px; z-index:1"
table border=1 bgcolor=eaffff width=175 height=50tdcenterbfont color="#D5D5D5"JavaScript Planet/font/b/center/td/table
/div
div id="object4" style="position:absolute; visibility:hide; left:175px; top:300px; z-index:1"
table border=1 bgcolor=eaffff width=175 height=50tdcenterbfont color="#C0C0C0"JavaScript Planet/font/b/center/td/table
/div
div id="object5" style="position:absolute; visibility:hide; left:175px; top:300px; z-index:1"
table border=1 bgcolor=eaffff width=175 height=50tdcenterbfont color="#b0b0b0"JavaScript Planet/font/b/center/td/table
/div
div id="object6" style="position:absolute; visibility:hide; left:175px; top:300px; z-index:1"
table border=1 bgcolor=eaffff width=175 height=50tdcenterbfont color="#939393"JavaScript Planet/font/b/center/td/table
/div
div id="object7" style="position:absolute; visibility:hide; left:175px; top:300px; z-index:1"
table border=1 bgcolor=eaffff width=175 height=50tdcenterbfont color="#808080"JavaScript Planet/font/b/center/td/table
/div
div id="object8" style="position:absolute; visibility:hide; left:175px; top:300px; z-index:1"
table border=1 bgcolor=eaffff width=175 height=50tdcenterbfont color="#6b6b6b"JavaScript Planet/font/b/center/td/table
/div
div id="object9" style="position:absolute; visibility:hide; left:175px; top:300px; z-index:1"
table border=1 bgcolor=eaffff width=175 height=50tdcenterbfont color="#424242"JavaScript Planet/font/b/center/td/table
/div
div id="object10" style="position:absolute; visibility:show; left:175px; top:300px; z-index:1"
table border=1 bgcolor=eaffff width=175 height=50tdcenterbfont color="#000000"JavaScript Planet/font/b/center/td/table
/divP
/FONT/CENTER
js代码,给我讲一下这段js代码,详细点, 尤其注明,#后边的是什么,date后边的代表什么?.val什么意思
你没有用过jquery吧?这是jquery的写法,jquery是一个js 库,封装了很多js方法
$ 是jquery的选择器,用来查找DOM元素,$("#name") 这个是其中一种写法,表示查找id="name"的元素,#后面跟id值
.val()是一个函数,用来获取或设置元素的value值,相当于
$("#name").val(o.quality) 相当于 document.getElementById("name").value= o.quality;
PS:建议你搜索一下jquery的相关资料
求一段js代码
这代码弄着不容易啊!!多给点分吧~~ 样式你回来自己写成喜欢的吧 功能没问题了!! 具体代码如下:
!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ""
html xmlns=""
head
meta http-equiv="Content-Type" content="text/html; charset=gb2312" /
title无标题文档/title
/head
script language="javascript"
function G(id){
return document.getElementById(id);
};
function GC(t){
return document.createElement(t);
};
String.prototype.trim = function(){
return this.replace(/(^\s*)|(\s*$)/g, '');
};
function isIE(){
return (document.all window.ActiveXObject !window.opera) ? true : false;
}
var loginDivWidth = 300;
var sign_in_flow = 'div style="background:#FF9900;"Login/divdiv用户名:/divdiv'
+ 'input type="text" id="sign_email" maxlength="64" size="30"/'
+ '/divdiv密码:/divdivinput type="password" id="sign_pwd" size="30"/'
+ '/divdivinput type="button" value="登录" onclick="signFlow(1);" id="sign_button"/ '
+ ' input type="button" value="取消" onclick="cancelSign();"//div';
function loadSignInFlow(){
G("sign_div").innerHTML = sign_in_flow;
G("sign_email").focus();
};
var sign_up_flow = 'div style="background:#CCFF00;"Create New Account/divdive-mail:*/divdiv'
+ 'input type="text" id="sign_email" maxlength="64" size="30"/'
+ '/divdivpassword:*/divdivinput type="password" id="sign_pwd" size="30"/'
+ '/divdivpassword again:*/divdivinput type="password" id="sign_repwd" size="30"/'
+ '/divdivinput type="button" value="creat account" onclick="signFlow(0);" id="sign_button"/ '
+ ' input type="button" value="cancel" onclick="cancelSign();"//div'
+ 'pa href="javascript:loadSignInFlow();"login/a/p';
function loadSignUpFlow(){
G("sign_div").innerHTML = sign_up_flow;
G("sign_email").focus();
};
function cancelSign(){
G("sign_div").style.display = 'none';
G("cover_div").style.display = 'none';
document.body.style.overflow = '';
};
var forget_pwd_flow = 'div style="background:#FF99FF;"Forget Password/divdive-mail:*/divdiv'
+ 'input type="text" id="sign_email" maxlength="64" size="30"/'
+ '/divdivinput type="button" value="sent pwd to e_mail" onclick="signFlow(2);" id="sign_button"/ '
+ ' input type="button" value="cancel" onclick="cancelSign();"//div';
function loadForgetPwdFlow(){
G("sign_div").innerHTML = forget_pwd_flow;
G("sign_email").focus();
};
function checkEmail(){
if(G("sign_email").value.trim() == ''){
return 'div style="color:#FF0000";"对不起用户名不能为空。/div';
}
return '';
}
function checkPwd(){
if(G("sign_pwd").value.trim() == ''){
return 'div style="color:#FF0000";"对不起密码不能为空。/div';
}
return '';
}
function checkRePwd(){
if(G("sign_pwd").value.trim() != G("sign_repwd").value.trim()){
return 'div style="color:#FF0000";"The specified passwords do not match./div';
}
return '';
}
function signFlow(isSignIn){
var error = checkEmail();
var htmlText = null;
if (isSignIn == 1) {
if (error == ''){
error = checkPwd();
}
htmlText = sign_in_flow;
} else if (isSignIn == 0) {
if (error == ''){
error = checkPwd();
if (error == ''){
error = checkRePwd();
}
}
htmlText = sign_up_flow;
} else if (isSignIn == 2) {
htmlText = forget_pwd_flow;
}
var eMailValue = G("sign_email").value.trim();
if (error == '') {
} else {
G("sign_div").innerHTML = error + htmlText;
G("sign_email").value = eMailValue;
}
};
function popCoverDiv(){
if (G("cover_div")) {
G("cover_div").style.display = '';
} else {
var coverDiv = GC('div');
document.body.appendChild(coverDiv);
coverDiv.id = 'cover_div';
with(coverDiv.style) {
position = 'absolute';
background = '#CCCCCC';
left = '0px';
top = '0px';
var bodySize = getBodySize();
width = bodySize[0] + 'px'
height = bodySize[1] + 'px';
zIndex = 98;
if (isIE()) {
filter = "Alpha(Opacity=60)";
} else {
opacity = 0.6;
}
}
}
}
function getBodySize(){
var bodySize = [];
with(document.documentElement) {
bodySize[0] = (scrollWidthclientWidth)?scrollWidth:clientWidth;
bodySize[1] = (scrollHeightclientHeight)?scrollHeight:clientHeight;
}
return bodySize;
}
function popSign(isLogin){
if (G("sign_div")) {
G("sign_div").style.display = '';
} else {
var signDiv = GC('div');
document.body.appendChild(signDiv);
signDiv.id = 'sign_div';
signDiv.align = "center";
signDiv.onkeypress = function(evt){
var e = window.event?window.event:evt;
if (e.keyCode==13 || e.which==13) {
if (G("sign_button")) {
G("sign_div").focus();
G("sign_button").click();
}
}
};
with (signDiv.style) {
position = 'absolute';
left = (document.documentElement.clientWidth - loginDivWidth)/2 + 'px';
top = (document.documentElement.clientHeight - 300)/2 + 'px';
width = loginDivWidth + 'px';
zIndex = 99;
background = '#FFFFFF';
border = '#66CCFF solid 1px';
}
}
if(isLogin) {
G("sign_div").innerHTML = sign_in_flow;
} else {
G("sign_div").innerHTML = change_pwd_flow;
}
}
function popSignFlow(isLogin) {
popCoverDiv();
popSign(isLogin);
document.body.style.overflow = "hidden";
if(isLogin) {
G("sign_email").focus();
} else {
G("old_pwd").focus();
}
}
function changePwd(){
var error = checkOldPwd();
if (error == ''){
error = checkPwd();
}
if (error == ''){
error = checkRePwd();
}
var oldPwd = G("old_pwd").value.trim();
var newPwd = G("sign_pwd").value.trim();
if (error == '') {
var url = basePath + "?q=tripuser/tripuser_change_pwd_ajax/" + oldPwd + "/" + newPwd;
exeRequest(url, getSignText, null);
} else {
G("sign_div").innerHTML = error + change_pwd_flow;
}
};
function checkOldPwd(){
if(G("old_pwd").value.trim() == ''){
return 'div style="color:#FF0000";"Old Password field is required./div';
}
return '';
}
var change_pwd_flow = 'div style="background:#33FFFF;"Change Your Password/divdivold password:*/divdiv'
+ 'input type="password" id="old_pwd" size="30"/'
+ '/divdivnew password:*/divdivinput type="password" id="sign_pwd" size="30"/'
+ '/divdivnew password again:*/divdivinput type="password" id="sign_repwd" size="30"/'
+ '/divdivinput type="button" value="change password" onclick="changePwd();" id="sign_button"/ '
+ ' input type="button" value="cancel" onclick="cancelSign();"//div';
/script
body
div
input type="button" onclick="popSignFlow(1);" value="登录"/
/div
/body
/html