引用 javascript基础知识


引用 javascript基础知识
2010年09月02日
  JS2010-09-02 21:08:47阅读0评论0  字号:大中小 订阅 引用 每一项都是js中的小技巧,但十分的实用! 
  1.document.write(""); 输出语句 
  2.JS中的注释为// 
  3.传统的HTML文档顺序是:document->html->(head,body) 
  4.一个浏览器窗口中的DOM顺序是:window->(navigator,screen,history,location,documen t) 
  5.得到表单中元素的名称和值:document.getElementById("表单中元素的ID号").name(或val) 
  6.一个小写转大写的JS: document.getElementById("output").val = document.getElementById("i
  nput").val.toUpperCase(); 
  7.JS中的值类型:String,Number,Boolean,Null,Object,Function 
  8.JS中的字符型转换成数值型:parseInt(),parseFloat() 
  9.JS中的数字转换成字符型:(""+变量) 
  10.JS中的取字符串长度是:(length) 
  11.JS中的字符与字符相连接使用+号. 
  12.JS中的比较操作符有:==等于,!=不等于,>,>=,Error,EvalError,Function,Math, Number,Object,RangeError,
  ReferenceError,RegExp,String,SyntaxError,TypeError ,URIError 
  53.JS中的换行:\n 
  54.窗口全屏大小: 
  55.JS中的all代表其下层的全部元素 
  56.JS中的焦点顺序:document.getElementByid("表单元素").tabIndex = 1 
  57.innerHTML的值是表单元素的值:如 
  "how are you" 
  ,则innerHTML的值就是:how are you 
  58.innerTEXT的值和上面的一样,只不过不会把这种标记显示出来. 
  59.contentEditable可设置元素是否可被修改,isContentEditable返回是否可修改的状态. 
  60.isDisabled判断是否为禁止状态.disabled设置禁止状态 
  61.length取得长度,返回整型数值 
  62.addBehavior()是一种JS调用的外部函数文件其扩展名为.htc 
  63.window.focus()使当前的窗口在所有窗口之前. 
  64.blur()指失去焦点.与FOCUS()相反. 
  65.select()指元素为选中状态. 
  66.防止用户对文本框中输入文本:onfocus="this.blur()" 
  67.取出该元素在页面中出现的数量:document.all.tags("div(或其它HTML标记符)").length 
  68.JS中分为两种窗体输出:模态和非模态.window.showModaldialog(),window.showModeless() 
  69.状态栏文字的设置:window.status='文字',默认的状态栏文字设置:window.defaultStatus = '文字.'; 
  70.添加到收藏夹:external.AddFavorite("http://www.dannyg.com"t;,"jaskdlf"); 
  71.JS中遇到脚本错误时不做任何操作:window.onerror = doNothing; 指定错误句柄的语法为:window.on
  error = handleError; 
  72.JS中指定当前打开窗口的父窗口:window.opener,支持opener.opener...的多重继续. 
  73.JS中的self指的是当前的窗口 
  74.JS中状态栏显示内容:window.status="内容" 
  75.JS中的top指的是框架集中最顶层的框架 
  76.JS中关闭当前的窗口:window.close(); 
  77.JS中提出是否确认的框:if(confirm("Are you sure?"))else{alert("Not Ok");} 
  78.JS中的窗口重定向:window.navigate("http://www.sina.com.cn"t;); 
  79.JS中的打印:window.print() 
  80.JS中的提示输入框:window.prompt("message","defaultReply"); 
  81.JS中的窗口滚动条:window.scroll(x,y) 
  82.JS中的窗口滚动到位置:window.scrollby 
  83.JS中设置时间间隔:setInterval("expr",msecDelay)或setInterval(funcRef,msecDelay)或setTimeou
  t 
  84.JS中的模态显示在IE4+行,在NN中不行:showModalDialog("URL"[,arguments][,features]); 
  85.JS中的退出之前使用的句柄:function verifyClose(){event.returnVal="we really like you and ho
  pe you will stay longer.";}} window.onbeforeunload=verifyClose; 
  86.当窗体第一次调用时使用的文件句柄:onload() 
  87.当窗体关闭时调用的文件句柄:onunload() 
  88.window.location的属性: protocol(http:),hostname(example.com),port(80),host(e
  xample.com:80),pathname("/a/a.html"),hash("#giantG izmo",指跳转到相应的锚记),href(全部的信
  息) 
  89.window.location.reload()刷新当前页面. 
  90.window.history.back()返回上一页,window.history.forward()返回下一页,window.history.go(返回
  第几页,也可以使用访问过的URL) 
  91.document.write()不换行的输出,document.writeln()换行输出 
  92.document.body.noWrap=tr;防止链接文字折行. 
  93.变量名.charAt(第几位),取该变量的第几位的字符. 
  94."abc".charCodeAt(第几个),返回第几个字符的ASCii码值. 
  95.字符串连接:string.concat(string2),或用+=进行连接 
  96.变量.indexOf("字符",起始位置),返回第一个出现的位置(从0开始计算) 
  97.string.lastIndexOf(searchString[,startIndex])最后一次出现的位置. 
  98.string.match(regExpression),判断字符是否匹配. 
  99.string.replace(regExpression,replaceString)替换现有字符串. 
  100.string.split(分隔符)返回一个数组存储值. 
  101.string.sstr(start[,length])取从第几位到指定长度的字符串. 
  102.string.toLowerCase()使字符串全部变为小写. 
  103.string.toUpperCase()使全部字符变为大写. 
  104.parseInt(string[,radix(代表进制)])强制转换成整型. 
  105.parseFloat(string[,radix])强制转换成浮点型. 
  106.isNaN(变量):测试是否为数值型. 
  107.定义常量的关键字:const,定义变量的关键字:var 
   javascript38种小技巧,推荐新手查看。
  捕获释放 
  event.srcElement.setCapture();  
  event.srcElement.releaseCapture();  
  事件按键
  event.keyCode 
  event.shiftKey 
  event.altKey 
  event.ctrlKey
  事件返回值
  event.returnVal
  鼠标位置 
  event.x 
  event.y
  窗体活动元素 
  document.activeElement
  绑定事件
  document.captureEvents(Event.KEYDOWN);
  访问窗体元素 
  document.all("txt").focus(); 
  document.all("txt").select();
  窗体命令
  document.execCommand
  窗体COOKIE 
  document.cookie
  菜单事件
  document.oncontextmenu
  创建元素 
  document.createElement("SPAN");  
  根据鼠标获得元素: 
  document.elementFromPoint(event.x,event.y).tagName =="TD 
  document.elementFromPoint(event.x,event.y).appendC hild(ms)  
  窗体图片
  document.images[索引]
  窗体事件绑定 
  document.onmousedown=scrollwindow;
  元素
  document.窗体.elements[索引]
  对象绑定事件 
  document.all.xxx.detachEvent('onclick',a);
  插件数目
  navigator.plugins
  取变量类型 
  typeof($js_libpath) == "undefined"
  下拉框 
  下拉框.options[索引] 
  下拉框.options.length
  查找对象
  document.getElementsByName("r1"); 
  document.getElementById(id); 
  定时 
  timer=setInterval('scrollwindow()',delay); 
  clearInterval(timer);
  UNCODE编码 
  escape() ,unescape
  父对象
  obj.parentElement(dhtml) 
  obj.parentNode(dom)
  交换表的行 
  TableID.moveRow(2,1) document.all.csss.href = "a.css";   
  替换CSS
  并排显示 
  display:inline 
  隐藏焦点 
  hidefocus=tr 
  根据宽度换行 
  style="word-break:break-all" 
  自动刷新 
   
  简单邮件 
    
  快速转到位置 
  obj.scrollIntoView(tr) 
  锚 
   
  anchors 
  网页传递参数 
  location.search(); 
  可编辑 
  obj.contenteditable=tr 
  执行菜单命令 
  obj.execCommand 
  双字节字符 
  /[^\x00-\xff]/ 
  汉字 
  /[\一-\

猜你喜欢

转载自lorws01p.iteye.com/blog/1359615