前端常用技巧

让文字在一行上下最好的居中方法:line-height: px

return关键字2个作用:1.结束函数 2.返回一个值给调用者

给容器设定尺寸, 不给图片设置尺寸,图片显示可能比容器大

 

var val = t.value; 获取文本框内容

var pVal = box.innerHTML;

var ary = pVal.split(val); //字符串切割完之后的到的是数组,不包括val的数组

var str=ary.join("<span>"+val+"</span>"); //join,将数组拼接成字符串

box.innerHTML=str; //将字符串写入网页之中

text-align: center; /*只能文档(字)居中,不能让图片居中*/ 可以继承

ins[1].onfocus = function(){

  spans[1].style.display = "none";

  spans[1].style.background= green;

}

 

.red{color: red;}

<div id="box">box</div>

 

//给某个元素点击只能切换颜色

$("#box").addClass("red").click(function(){

// $(this).removeClass("red");

$(this).toggleClass("red"); //this指id名为box对应的标签

});

 

//让网页禁止选择、复制、右键

<body leftmargin=0 topmargin=0 oncontextmenu='return false' ondragstart='return false' onselectstart ='return false' onselect='document.selection.empty()' oncopy='document.selection.empty()' onbeforecopy='return false' onmouseup='document.selection.empty()'>

//相关设置

oncontextmenu='return false'
ondragstart='return false' 
onselectstart ='return false' 
onselect='document.selection.empty()' 
oncopy='document.selection.empty()' 
onbeforecopy='return false' 
onmouseup='document.selection.empty()'

 

//让网页禁止复制

<body onmousemove=/HideMenu()/ oncontextmenu="return false" ondragstart="return false" onselectstart ="return false" onselect="document.selection.empty()" oncopy="document.selection.empty()" onbeforecopy="return false" onmouseup="document.selection.empty()">

 

//通过JS的方式禁止复制,选择

document.oncontextmenu=new Function("event.returnValue=false");
document.onselectstart=new Function("event.returnValue=false");

 

 //禁止页面打印(其实是打印空的)

<style>

@media print{

body{display:none}

}

</style>

转载于:https://www.cnblogs.com/binghuaZhang/p/10780982.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值