js使用小技巧

js使用小技巧

--------------------------------------------------------------------------------

1.收藏时用图标显示

<link REL="SHORTCUT ICON" href="http://www.asp888.net/site.ico">

2.TD内容实现不换行

只要使用noWrap属性即可

3.获得客户端文件大小

<img src="http://www.webucn.com/web/images/banner.gif" οnmοuseοver="this.alt='文件大小为:'+this.fileSize+'字节'">

4.动态删除元素

img1.removeNode(true)
5.模拟按键:
var WshShell = new ActiveXObject("WScript.Shell");
WshShell.sendKeys("{F11}");
6.以下语句不需要纠错判断

for(i=2;i<1;i++){}

7.把js文件群打包掉用

<script archive=utils.jar src=animation.js></script>

8.获得当前选中文本

document.getSelection()

9.获得对象在document.all[]中元素的下标

txt1.sourceIndex

10.滚动文档到窗口顶部或底部

txt1.scrollIntoView(true)

11.段落自动缩进

<p style=text-indent:26px>内容</p>

12.客户端IP地址

Request.ServerVariables("REMOTE_HOST")

13.元素投影(可彻底解决网页中投影问题)

filter:progid:DXImageTransform.Microsoft.Shadow(color='gray',Direction=135, Strength=3)

14.图片热区焦点隐藏

<img hideFocus>

15.不能在onload事件中open窗口,否则会被拦截

16.选择本地文件时改变图片源

<input type="file" onpropertychange="img.src=value">

17.获取文件路径

var str = "http://localhost/Home/manage/FCKeditor/dialog/fck_image.html"; str = str.replace(/[^//]+$/,"");

18.js中的trim

String.prototype.trim = function()
{
  return this.replace(/(^[/s]*)|([/s]*$)/g, "");
}

19.定义样式表的子元素样式

.cls button{color:red}

21.文本框tab

<textarea οnkeydοwn="if(event.keyCode==9){clipboardData.setData('Text', '    ');execCommand('paste');return false}" rows=8 cols=28>
</textarea>

22.最大化窗口

<OBJECT classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11" onreadystatechange="if (this.readyState==4) this.Click();" VIEWASTEXT><PARAM name="Command" value="Maximize"></OBJECT>

23.图片title换行符

&#13;

24.对body的click事件重定义

document.body.οnclick=function(){ alert() }

25.10进制转换为16进制

alert((255).toString(16))

26.隐藏链接提示

<style> 
a  {evt:expression(window.status='')} 
</style> 
<a  href=http://ywicc.com>no  status  information</a>

注意:expression为获焦或失焦时执行,可为寄主创建一参数,使其只执行一次,用于表格控制

27.同时执行两事件

function document.onclick,document.onkeydown(){
   window.alert('Hello World!!!');
}

28.不显示图片工具栏

<meta http-equiv="imagetoolbar" content="no">

29.页面最大化

<OBJECT classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11" onreadystatechange="if (this.readyState==4) this.Click();" VIEWASTEXT><PARAM name="Command" value="Maximize"></OBJECT>

30.提交到新的可自义窗口

<form method="post" action="1.htm" target="test" onSubmit="window.open('','test','width=100,height=100')">
<input type="submit">
</form>

31.用css控制表格间隔色

tr{background:expression(this.rowIndex%2==0 ? "red":"")}

32.取得字符的asc码

"s".charCodeAt(0)

33.获得行对象所在行数

o.rowIndex

34.去掉最后一个字符

s.slice(0,-1)

35.获得系统背景色

style=background:buttonface

36.表格导出为excel文件

客户端提供链接,在服务器端输出xls文件,由客户保存到客户端即可

服务器端改变文件名的方法是

Response.ContentType = "application/vnd.ms-excel"

Response.AddHeader("Content-Disposition", "attachment;filename=demo.exe")

37.在模式窗口中链接

<base target="_self">

38.求两点夹角

Math.atan2(y1-y0, x1-x0)*180/Math.PI
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值