整合营销服务商

电脑端+手机端+微信端=数据同步管理

免费咨询热线:

Html代码常用功能,很资源噢!(中)

. 将彻底屏蔽鼠标右键

<table border oncontextmenu=return(false)><td>no</table> 可用于Table

2. <body> 取消选取、防止复制

3. 不准粘贴

4. 防止复制

5. <link rel="Shortcut Icon" href="favicon.ico"> IE地址栏前换成自己的图标

6. <link rel="Bookmark" href="favicon.ico"> 可以在收藏夹中显示出你的图标

7. <input style="ime-mode:-Disabled"> 关闭输入法

8. 永远都会带着框架

<script language="javascript"><!--

if (window == top)top.location.href = "frames.htm"; //frames.htm为框架网页

// --></script>

9. 防止被人frame

<SCRIPT LANGUAGE=javascript><!--

if (top.location != self.location)top.location=self.location;

// --></SCRIPT>

10. 网页将不能被另存为

<noscript><iframe src=*.html></iframe></noscript>

11. <input type=button value=查看网页源代码

onclick="window.location = `view-source:`+ http://www.51js.com/`";>

12.删除时确认

<a href=`javascript:if(confirm("确实要删除吗?"location="boos.asp?&areyou=删除&page=1"`>删

除</a>

13. 取得控件的绝对位置

//javascript

<script language="javascript">

function getIE(E){

var t=e.offsetTop;

var l=e.offsetLeft;

while(e=e.offsetParent){

t+=e.offsetTop;

l+=e.offsetLeft;

}

alert("top="+t+"/nleft="+l);

}

</script>

//VBScript

<script language="VBScript"><!--

function getIE()

dim t,l,a,b

set a=document.all.img1

t=document.all.img1.offsetTop

l=document.all.img1.offsetLeft

while a.tagName<>"BODY"

set a = a.offsetParent

t=t+a.offsetTop

l=l+a.offsetLeft

wend

msgbox "top="&t&chr(13)&"left="&l,64,"得到控件的位置"

end function

--></script>

14. 光标是停在文本框文字的最后

<script language="javascript">

function cc()

{

var e = event.srcElement;

var r =e.createTextRange();

r.moveStart(`character`,e.value.length);

r.collapse(true);

r.select();

}

</script>

<input type=text name=text1 value="123">

15. 判断上一页的来源

javascript:

document.referrer

16. 最小化、最大化、关闭窗口

<object id=hh1 classid="clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11">

<param name="Command" value="Minimize"></object>

<object id=hh2 classid="clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11">

<param name="Command" value="Maximize"></object>

<OBJECT id=hh3 classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11">

<PARAM NAME="Command" value="Close"></OBJECT>

<input type=button value=最小化 onclick=hh1.Click()>

<input type=button value=最大化 onclick=hh2.Click()>

<input type=button value=关闭 onclick=hh3.Click()>

本例适用于IE

17.屏蔽功能键Shift,Alt,Ctrl

<script>

function look(){

if(event.shiftKey)

alert("禁止按Shift键!"; //可以换成ALT CTRL

}

document.onkeydown=look;

</script>

18. 网页不会被缓存

<META HTTP-EQUIV="pragma" CONTENT="no-cache">

<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate">

<META HTTP-EQUIV="expires" CONTENT="Wed, 26 Feb 1997 08:21:57 GMT">

或者<META HTTP-EQUIV="expires" CONTENT="0">

19.怎样让表单没有凹凸感?

<input type=text style="border:1 solid #000000">

<input type=text style="border-left:none; border-right:none; border-top:none; border-bottom:

1 solid #000000"></textarea>

20.<div><span>&<layer>的区别?

<div>(division)用来定义大段的页面元素,会产生转行

<span>用来定义同一行内的元素,跟<div>的唯一区别是不产生转行

<layer>是ns的标记,ie不支持,相当于<div>

21.让弹出窗口总是在最上面:

<body>

22.不要滚动条?

让竖条没有:

<body style=`overflow:-Scroll;overflow-y:hidden`>

</body>

让横条没有:

<body style=`overflow:-Scroll;overflow-x:hidden`>

</body>

两个都去掉?更简单了

<body scroll="no">

</body>

23.怎样去掉图片链接点击后,图片周围的虚线?

<a href="#"><img src="logo.jpg" border=0></a>

24.电子邮件处理提交表单

<form name="form1" method="post" action="mailto:****@***.com" enctype="text/plain">

<input type=submit>

</form>

25.在打开的子窗口刷新父窗口的代码里如何写?

window.opener.location.reload()

26.如何设定打开页面的大小

<body>

打开页面的位置<body>

27.在页面中如何加入不是满铺的背景图片,拉动页面时背景图不动

<style>

body

{background-image:url(logo.gif); background-repeat:no-repeat;

background-position:center;background-attachment: fixed}

</style>

String 对象用于处理已有的字符块。

JavaScript 字符串

一个字符串用于存储一系列字符就像 "John Doe".

一个字符串可以使用单引号或双引号:

实例

var carname="Volvo XC60";

var carname='Volvo XC60';

你使用位置(索引)可以访问字符串中任何的字符:

实例

var character=carname[7];

字符串的索引从零开始, 所以字符串第一字符为 [0],第二个字符为 [1], 等等。

你可以在字符串中使用引号,如下实例:

实例

var answer="It's alright";

var answer="He is called 'Johnny'";

var answer='He is called "Johnny"';

或者你可以在字符串中使用转义字符使用引号:

实例

var answer='It's alright';

var answer="He is called "Johnny"";


字符串(String)

字符串(String)使用长度属性length来计算字符串的长度:

实例

var txt="Hello World!";

document.write(txt.length);

var txt="ABCDEFGHIJKLMNOPQRSTUVWXYZ";

document.write(txt.length);

在字符串中查找字符串

字符串使用 indexOf() 来定位字符串中某一个指定的字符首次出现的位置:

实例

var str="Hello world, welcome to the universe.";

var n=str.indexOf("welcome");

如果没找到对应的字符函数返回-1

lastIndexOf() 方法在字符串末尾开始查找字符串出现的位置。

内容匹配

match()函数用来查找字符串中特定的字符,并且如果找到的话,则返回这个字符。

实例

var str="Hello world!";

document.write(str.match("world") + "<br>");

document.write(str.match("World") + "<br>");

document.write(str.match("world!"));

替换内容

replace() 方法在字符串中用某些字符替换另一些字符。

实例

str="Please visit Microsoft!"

var n=str.replace("Microsoft","w3cschool");

字符串大小写转换

字符串大小写转换使用函数 toUpperCase() / toLowerCase():

实例

var txt="Hello World!"; // String

var txt1=txt.toUpperCase(); // txt1 文本会转换为大写

var txt2=txt.toLowerCase(); // txt2 文本会转换为小写

字符串转为数组

字符串使用split()函数转为数组:

实例

txt="a,b,c,d,e" // String

txt.split(","); // 使用逗号分隔

txt.split(" "); // 使用空格分隔

txt.split("|"); // 使用竖线分隔

特殊字符

Javascript 中可以使用反斜线(\)插入特殊符号,如:撇号,引号等其他特殊符号。

查看如下 JavaScript 代码:

var txt="We are the so-called "Vikings" from the north.";

document.write(txt);

在JavaScript中,字符串的开始和停止使用单引号或双引号。这意味着,上面的字符串将被切成: We are the so-called

解决以上的问题可以使用反斜线来转义引号:

var txt="We are the so-called \"Vikings\" from the north.";

document.write(txt);

JavaScript将输出正确的文本字符串:We are the so-called "Vikings" from the north.

下表列出其他特殊字符,可以使用反斜线转义特殊字符:

代码输出
\'单引号
\"双引号
\斜杆
\n换行
\r回车
\ttab
\b空格
\f换页

字符串属性和方法

属性:

  • length

  • prototype

  • constructor

方法:

  • charAt()

  • charCodeAt()

  • concat()

  • fromCharCode()

  • indexOf()

  • lastIndexOf()

  • match()

  • replace()

  • search()

  • slice()

  • split()

  • substr()

  • substring()

  • toLowerCase()

  • toUpperCase()

  • valueOf()

如您还有不明白的可以在下面与我留言或是与我探讨QQ群308855039,我们一起飞!

s点击下载文件

//点击下载文件写法
const w = window.open('about:blank');
w.location.href='文件url'

PC端中px转vw与vh,sass写法

//PC端 px转vwvh 写法 sass
@function px-vw($px) {
  @return $px*100/3840*1vw
}
@function px-vh($px) {
  @return $px*100/2160*1vh
}

sass实现纵向滚动条,并改变滚动条样式

//滚动条
height:300px;
overflow-x: hidden;
overflow-y: scroll;
&::-webkit-scrollbar {
    width: 5px;
    height: 5px;
}
/*定义滚动条轨道 内阴影+圆角*/
&::-webkit-scrollbar-track {
    box-shadow: inset 0 0 0px rgba(240, 240, 240, .5);
    border-radius: 10px;
}
/*定义滑块 内阴影+圆角*/
&::-webkit-scrollbar-thumb {
    border-radius: 10px;
    box-shadow: inset 0 0 0px rgba(240, 240, 240, .5);
    background-color: #1890ff;
}

css实现竖条背景 内部百分比设置

//竖条背景
background-size:8px;
background-image: linear-gradient(90deg,#52e9ff 50%,#fff);

sass禁止文字换行 在新样式中引用样式

//禁止文字换行
.ellipsis{
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

//引用样式class
@extend .ellipsis;

css改变鼠标指针为手型

//改变鼠标指针为手型
cursor: pointer;

css背景样式渐变为透明色

//背景颜色渐变 transparent
background-image: linear-gradient(90deg, red, transparent);

sass中修改引用了antd组件的样式

//sass修改antd样式
:global(.className){}

css取第一个子元素与取最后一个子元素

//css取第一个
&:nth-child{}
&:first-child{}
//css取最后一个
&:last-child{}

js保留一位小数