JavaScript
共 27 篇文章
JS窗口改变触发事件
var resizeTimer = null; function doResize(){ var url = '${ctx}/aa/monitor/alar/recharge.jsp'; window.location.href = url; //alert("width="+document.documentElement.clientWidth + " Height="+document.documentElement.clientHeight); } window.onresize = function(){ if(resizeTimer) clearTimeout(resizeTim…
2011-04-28 17:32 · JavaScript
js动态生成表格,然后清空
var tBodyObj = document.getElementById( "ruleDetail" ); var n = tBodyObj.firstChild; while(n) { var m = n.nextSibling; tBodyObj.removeChild(n); n = m; }
2011-04-11 16:41 · JavaScript
Javascript刷新页面的几种方法
Javascript刷新页面的几种方法 : 1. history.go(0) 2. location.reload() 3. location=location 4. location.assign(location) 5. document.execCommand( 'Refresh ') 6. window.navigate(location) 7. location.replace(location) 8.document.URL=location.href ----------------------------------------------------------------…
2010-07-02 15:48 · JavaScript
JS客户端验证
demo1: <html> <head> <title>JavaScript中使用正则表达式</title> <script language="javascript"> function validate(form){ var num = form.number.value; if(!/^[0-9]*$/.test(num)){ alert("输入的不是数字请重新输入数字"); return false; } return true; } </script> </head> <body> <form action="aa" method="post" onSubmit="return va…
2010-03-26 17:24 · JavaScript
form表单提交2次的原因
1.第一种写法: (1)<form name="loginForm" action="login" method="post" id="loginForm"> <input type="button" value="tijiao" onclick="return checkField();"/> </form> (2)function checkField(){ if(usernameValue !== "" && passwordValue !== ""){ document.getElementById("loginForm").submit(); return true; } } 2.…
2010-03-24 14:32 · JavaScript
如何判断年龄大于18岁
1.jquery的实现方式: 下面这个: (1)var birth = document.getElementById("dateBirth").children[1].value; 它是用来获取struts2.0的日期控件,输入日期然后获取输入值的方式。 (2)var agree = document.signupFormSubmit.ch1Agree.checked; 它是用来获取chekbox复选框,是否被选中。如果选中则为true,否则是false。 <script type='text/javascript'> $(function(){ $("#signupFormSubmit"…
2010-03-14 15:09 · JavaScript
java IE火狐兼容添加到收藏夹 IE7浏览器状态栏报错,"找不到元素"或者"没有权限"
java IE火狐兼容添加到收藏夹的java代码: function addToBookmark() { var url = document.location.href; if(window.sidebar){ window.sidebar.addPanel("MonsterBig", url,""); }else if(document.all){ window.external.addFavorite(url, "MonsterBig"); }else if(window.opera && window.print){ return true; } } 上面的代码是正确的。至于碰到的浏…
2010-03-08 11:58 · JavaScript
JS来获取页面的URL top.location.href 和 window.location.href
JS来获取页面的URL: (1)普通的格式是:window.location.href (2)但是如果是登录时候先弹出个对话框,这个对话框里面是登录的页面login.jsp,这个时候在这个对话框里面如果想获取最外层的url的方式,就必须用 top.location.href 了。 例子如下: var strHref = top.document.location.href; var intPos = strHref.indexOf("#"); var strRight = strHref.substr(0,intPos); if(num == "success"){ top.location…
2010-03-03 11:31 · JavaScript
Dom的“事件类型”和“事件监听”
代码一:普通的写法(简单写法) <html> <title></title> <head> <script type="text/javascript"> function clickme(){ alert(88); } </script> </head> <body> <div id="click" onclick="javascript:clickme();">click me</div> </body> </html> 代码二:有时候可以解决跨浏览器的写法(要掌握这种写法的思想)。这种写法叫“事件的监听”。 <html> <title></title> <head> <script t…
2010-01-22 15:21 · JavaScript
JS如何关闭flash代码
1.在index.html页面的<head>里面加入: <head> <script src="js/flash.js" type="text/javascript"></script> </head> 2.在index.html的body里面加入: <body> <div id="Javascript.Div2" class="div" onclick="Javascript:closeD();" style="width: 240px; height:90px" align="center">点击关闭它 <script language="javascript" type="text/j…
2010-01-20 17:53 · JavaScript
document.documentElement.scrollTop
要获取当前页面的滚动条纵坐标位置,用: document.documentElement.scrollTop; 而不是: document.body.scrollTop; documentElement 对应的是 html 标签,而 body 对应的是 body 标签。 在标准w3c下,document.body.scrollTop恒为0,需要用document.documentElement.scrollTop来代替 如果你想定位鼠标相对于页面的绝对位置时,你会发现google里面1000篇文章里面有999.99篇会让你使用event.clientX+document.body.scrol…
2010-01-19 16:42 · JavaScript
JQuery 模式对话框DIV
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>jquery弹出层实例</title> <script type="text/javascrip…
2010-01-19 16:40 · JavaScript
JQuery 随鼠标滚动条滚动的div
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>无标题文档</title> <script type="text/javascript" src…
2010-01-19 15:56 · JavaScript
JS中定义变量i自增长
<script> var i = 1; function makePage(temp){ totalcount = '<s:property value="#request.pagerpic.getTotalPage()"/>'; if(temp > 0){ if(i<totalcount){ i++; document.getElementById("pic").src='Page.action?returnPage=viewpicture&classId=<s:property value="#request.scene.id"/>&currPage='+i; document.getE…
2009-12-07 10:37 · JavaScript
用iframe来实现一个页面嵌套另一个页面
用iframe来实现一个页面嵌套另一个页面,以此来实现页面局部动态刷新,就像AJAX做的效果。 用struts2.0做的: <iframe id="pic" name="pic" width="100%" scrolling="no" onload="this.height=pic.document.body.scrollHeight" frameborder="0" src="Page.action?returnPage=viewpicture&classId=<s:property value="#request.scene.id"/>&currPage=<s:property valu…
2009-12-06 10:04 · JavaScript
(全选)多选按钮的JS实现 单选按钮
1.代码:(全选)多选按钮 <html> <head> <title>复选框checked属性</title> <script language="JavaScript" type="text/javascript"> <!-- function myFunction() { var bBoolean = document.myForm2.cb.checked; if(bBoolean){ document.myForm1.cb1.checked = true; document.myForm1.cb2.checked = true; document.myForm1.cb3.checked…
2009-11-13 10:53 · JavaScript
JS创建数组的方法
var myArray = new Array(); var min_row = Math.min.apply(Math,myArray); myArray.shift(); //去掉第一个数 一、创建数组 <script language="JavaScript" type="text/javascript"> <!-- var myArray = new Array(7); myArray[0] = "Sunday"; myArray[1] = "Monday"; myArray[2] = "Tuesday"; myArray[3] = "Wednesday"; myArray[4] =…
2009-11-12 10:21 · JavaScript
JS和JSP的共同使用(JS的字符串定义、null值的判断、变量的定义)
1.signin.jsp <% String errMessage = null; Object obj = request.getAttribute("errorinfo"); if(obj != null){ errMessage = obj.toString().trim().toLowerCase(); } %> <script type="text/javascript"> function errorLogin(){ var num = String("<%=errMessage%>"); if(num !== "null"){ document.getElementById("…
2009-11-10 11:32 · JavaScript
JS如何传参的问题
1. 页面:这里需要注意radio不能写id,如果写了id的属性后就不能正常显示raido,所以没办法就只能在js中用this.value来获取div1。这个div1、div2、div3实际上是3个对话框的id属性值。只能想办法这样来获取它的id了。 <input name="quest20" type="radio" value="div1" disabled onclick="javascript:openDivDiag(this);"/> <input name="quest20" type="radio" value="div2" disabled onclick="javascri…
2009-11-03 11:11 · JavaScript
CMS模板发布中的div框
<div id="createFile" style="display: none; z-index: 1; position: absolute; left: 500px; top: 300px; width: 350px; height: 200px; background: white; border: 1px solid black;"> <div style="z-index: 3; position: absolute;width:500px;height:150px;padding-top:10px;padding-left:10px;"> <h:outputLabel sty…
2009-11-02 23:04 · JavaScript