<!DOCTYPE html> <html> <head> </head> <body> <script type="text/javascript">function isWindow( obj ) {/* jshint eqeqeq: false */return obj != null && obj == obj.window;};function test(){console.log(this);console.log(this.window);console.log(isWindow(this));}test(); </script> </body> </html> 原文:http://www.cnblogs.com/ghgyj/p/4006645.html
<script> window["MzBrowser"]={};(function() { if(MzBrowser.platform) return; var ua = window.navigator.userAgent; MzBrowser.platform = window.navigator.platform; MzBrowser.firefox = ua.indexOf("Firefox")>0; MzBrowser.opera = typeof(window.opera)=="object"; MzBrowser.ie = !MzBrowser.opera && ua.indexOf("MSIE")>0; MzBrowser.mozilla = window.navigator.product == "Gecko"; MzBrowser.netscape= window.na...
关闭页面的时候弹出提示框 <!doctype html> <html> <head> <meta charset="UTF-8"> <title>Leave Page</title> <script type="text/javascript"> window.onbeforeunload = function() { return "Leave this page?"; } </script> </head> <body> Contents... </body> </html> 原文:http://www.cnblogs.com/batter152/p/4285419.html
function isPrime(p){//判断0,1非数字等特殊数值,失败重新进行 if(p==0||p==1||isNaN(p)){ p = prompt(‘素数判断‘,‘不能输入1或非数字,请重新输入‘); isPrime(p); return false; }//判断2 if(p==2){ document.write(p+"是素数!"); return false; }//将合数过滤 for(var i=2;i < p;i++){ if(p%i == 0){ document.write(p+"是合数!"); return false; } };//最后只剩下素数了 document.write(p+"是素数!");}//...
想要的效果:比如说返回 25% 12.5% 33.33% 有几位小数就显示几位,就用 a=Math.round(a*100)/100 如果想要强制返还两位小数,就使用 a=a.toFixed(2); 问题2:JavaScript中判断 0=="" 返回true,所以要使用=== 在 JavaScript 里,null,0,””,false,和 undefined 全部彼此相等(==),因为它们的计算值都为 ‘false问题3:JavaScript的短路效应对于逻辑运算符&& 和 ||,学过discr...
ie浏览器和edge浏览器,必须用Adobe Reader PDF阅读器才可以打开pdf文件,其他现代浏览器自带pdf阅读器,无需安装。判断ie或者edge如果安装了,就浏览pdf文件;如果没安装就给出安装软件,让他下载、<!DOCTYPE html> <html><head><meta charset="UTF-8"><title></title><script src="jquery-1.10.2_d88366fd.js"></script></head><body><img src="myzh_yitou03.png" class="aaa"/></body><script>$(function(){function isAcrobat...
/判断手机横竖屏状态: function hengshuping(){ if(window.orientation==180||window.orientation==0){ alert("竖屏状态!") } if(window.orientation==90||window.orientation==-90){ alert("横屏状态!") } } window.addEventListener("onorientationchange" in window ? "orientationchange" : "resize", hengshuping, false); //移动端的浏览器一般都支持window.orien...
var UA = function(){ var userAgent = navigator.userAgent.toLowerCase(); return { ipad: /ipad/.test(userAgent), iphone: /iphone/.test(userAgent), android: /android/.test(userAgent), weixin: /micromessenger/.test(userAgent), qqnews_version: userAgent.match(/qqnews/i) == "qqnews" ? userAgent.split(‘qqnews/‘)[1] : ‘‘ }; }本文出自 “让希望不再失望...
<script> if(location.href.indexOf(‘//y.qq.com‘)!=-1){ document.write("<script>document.domain = ‘qq.com‘;<\/script>"); }else { document.write("<script>document.domain = ‘qqmusic.com‘;<\/script>"); } </script> 原文:https://www.cnblogs.com/ysbl/p/11922987.html
function CheckBrowser() {ua = navigator.userAgent;ua = ua.toLocaleLowerCase();var browserVersion;if (ua.match(/msie/) != null || ua.match(/trident/) != null) {browserType = "IE";//哈哈,现在可以检测ie11.0了!browserVersion = ua.match(/msie ([\d.]+)/) != null ? ua.match(/msie ([\d.]+)/)[1] : ua.match(/rv:([\d.]+)/)[1];} else if (ua.match(/firefox/) != null) {browserType = "火狐";} else if (ua.match...
var ua = navigator.userAgent.toLowerCase(); var isWeixin = ua.indexOf(‘micromessenger‘) != -1; var isAndroid = ua.indexOf(‘android‘) != -1; var isIos = (ua.indexOf(‘iphone‘) != -1) || (ua.indexOf(‘ipad‘) != -1); if (isWeixin || isAndroid || isIos) {//手机访问 }else{//电脑访问 } if (isWeixin) {//微信访问 } if (isAndroid) {//安卓访问 } if (isIos) {...
这个主要是根据所有的值,按顺序输出,如果没有值,就给予空的占位, //页面加载的时候获取左边和右边的所有游客id var array_left_start = new Array(); var array_right_start = new Array(); var tourist_left_start=new Array(); var tourist_right_start=new Array(); $(function(){ $(".left_table").find("input[name=‘tourist_id‘]").each(function(i,item){ array_left_sta...
JQuery:var $isChecked = $("#id").is(":checked");alert($isChecked);JS:var $id = document.getElementById("id");alert($id.checked); Notes:JQuery中,is函数里的必须要有冒号,否则不见效;JS中,必须调用checked 即>>> .checked原文:http://www.cnblogs.com/vincentExclusiveBlog/p/5353464.html
最近做的一个网站页面中需要根据用户的访问设备的不同来显示不同的页面样式,主要是判断移动设备还是电脑浏览器访问的。下面给出js判断处理代码,以作参考。<script type="text/javascript">function browserRedirect() {var sUserAgent = navigator.userAgent.toLowerCase();var bIsIpad = sUserAgent.match(/ipad/i) == "ipad";var bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os";var bIsMidp = sUserAgent.match...
<!DOCTYPE html> <html> <head lang="en"><meta charset="UTF-8"><title>addclass,removeclass,hasclass,toggleclass,getbyclass</title> </head> <body> <div class="div1" id="box1"></div> <input type="button" value="按钮" id="btn1"/> <script>function addClass(obj,cls) {//obj:要添加classname的元素,cls:要添加的classname;//如果原来没有class:if(obj.className == ‘‘){obj.className = cls;} else {//本来已经有c...