JavaScript获取Select当前值写法:var value = document.getElementById("select").options[document.getElementById("select").options.selectedIndex].value;var text = document.getElementById("select").options[document.getElementById("select").options.selectedIndex].text; 例子: 代码如下:<script>function check() { var select = document.getElementById("select").options[document.getElementById("select"...
代码如下:<head> <script> function EnterPress(e){ //传入 event var e = e || window.event; if(e.keyCode == 13){ document.getElementById("txtB").focus(); } } </script> </head> <body> <input type="text" id="txtA" onkeypress="EnterPress(event)" onkeydown="EnterPress()" /> <input type="text" id="txtB" /> </body>
由于chrome,safari,opara 浏览器还未支持自动 "设为首页" & "加入收藏". 所以我们只能try, catch一下, 给个错误提示! 也算完美了. 另外ie中, 很多人也碰到过 它window.external.addFavorite. 时会报错的问题. 所以俺也只好抛出提示信息了. 加入收藏: 代码如下:function addFavorite(){ if (document.all){ try{ window.external.addFavorite(window.location.href,document.title); }catch(e){ ...
代码如下:<mce:script type="text/javascript"><!--function copyToClipboard(meintext){ //ie if (window.clipboardData){ window.clipboardData.setData("Text", meintext); } else if (window.netscape) { try { netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); } catch(e) { alert("被浏览器拒绝!"); ///n请在浏...
代码如下:document.onkeydown=function(e){ var e=window.event||e; var element=e.srcElement||e.target; if(e.keyCode==13&&element.type!="submit"&&element.type!="button"&&element.type!="textarea"&&element.type!="reset"){ if(document.all){ e.keyCode=9; }else{ getNextInput(element).focus(); e.preventDefault(); } }}function getNextInput(inp...
代码如下:<body> <input type=file id="j" onchange="getValue();" style="-moz-opacity:0;filter:alpha(opacity=0);opacity:0;position:absolute;left:166px;" /> <input id="ye" style="color: green;border: 1px solid green;width:300px;" /> <input type="button" value="File" style="border: 1px solid green;width:80px;" /> </body> <script language="javascript"> function getValue(){ document.getElementById(ye).va...
前言 在开发过程中,因为之前有接触过Discuz,就直接拿其common.js里面的getcookie和setcookie方法来使用,做到后面在使用IE来测试的时候,发现这两个方法子啊IE下不起作用,就请教同事,这样就有了jquery.cookie.js文件的由来,里面的代码很少,我贴在下面,方便以后使用和研究吧。 源码 代码如下:/** * Cookie plugin * * Copyright (c) 2006 Klaus Hartl (stilbuero.de) * Dual licensed under the MIT and GPL licenses: * ht...
这个功能主要是解决内容页中的图片过大撑出,导致页面比较难看,就需要这样的代码,需要的朋友可以参考下 需求:图片width<=600px,height<=800。 1、利用max-width,max-height使图片等比例自动缩放代码: 代码如下:img{max-width: 600px;max-height: 800px;} 由于ie6不支持css max-width,max-height,所以在ie6中需要利用javascript脚本来控制大小。 2、用javascript脚本来兼容ie6,代码如: 代码如下:var img_width = img.Offse...
xml结构如下 代码如下:<ad><tupian>http://www.seehaha.com/images/060901-150.100.2.gif</tupian><tupian>http://www.seehaha.com/xml/061009-300.100.jpg</tupian><dizhi>http://www.seehaha.com/plan/</dizhi><dizhi>http://www.seehaha.com/va.htm</dizhi></ad>== // JScript 文件 var Now = new Date(); var Min = Now.getSeconds(); var i; if((Min % 2) == 1)//读取秒数,根据奇偶随机轮换,当然也可以...
代码如下:function clickButton(id) { if (document.all) { document.getElementById(id).click(); } else { var evt = document.createEvent("MouseEvents"); evt.initEvent("click", true, true); document.getElementById(id).dispatchEvent(evt); } }
代码如下:var xPos; var yPos; document.onmousemove = mouseMove; function mouseMove(ev) { ev = ev window.event; var mousePos = mouseCoords(ev); xPos = mousePos.x; yPos = mousePos.y; } function mouseCoords(ev) { if (ev.pageX ev.pageY) { return { x: ev.pageX, y: ev.pageY }; } return { x:ev.clientX+document.body.scrollLeft+document.documentElement.scrollLeft, y:ev.clientY + document.body.scrollTop + do...
代码如下: function GetDay() { var arrDate, objDate1, objDate2, intDays; objDate1 = new Date(); objDate2 = new Date(); arrDate = $("#开始日期").val().split("-"); objDate1.setFullYear(arrDate[0], arrDate[1], arrDate[2]); arrDate = $("#结束日期").val().split("-"); objDate2.setFullYear(arrDate[0], arrDate[1], arrDate[2]); intDays = parseInt(Math.abs(objDate1 - objDate2) / 100...
实例代码一见: 代码如下:<!DOCTYPE HTML> <html> <head> <style type="text/css"> #main div{position:absolute;width:220px;height:150px;border:1px solid #999;} </style> <script type="text/javascript"> var a; document.onmouseup = function() { if (!a) return; a = ""; }; document.onmousemove = function(d) { if (!a) return; d=d||event; a.style.left = (d.clientX - b) + "px"; a.style.top = (d.clientY - c) +...
注意使用preventDefault防止浏览器的默认事件操作发生 代码如下:<script language="javascript" type="text/javascript"> var isDrag = false; function isIE(){ if(navigator.userAgent.indexOf("MSIE")>0){return true;} else{return false;} } function addListener(element,e,fn){ if(isIE()){element.attachEvent("on" + e,fn);} else{element.addEventListener(e,fn,false);} } function drag(e){ var e = e || window.even...
效果图如下: 代码如下: 代码如下:<!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=utf-8" /> <title>本地图片预览</title> <style type="text/css"> #preview{width:100px;height:100px;border:1px solid #000;overflow:hidd...