日期:2014-05-16  浏览次数:20387 次

常用js代码大全2

常用js代码大全2

二,高级应用(一)

????????? 页面跳转:

  window.location.href('地址')
  window.open('地址', '_self')
打开新窗口:
  window.open('地址', '_blank')
  只显示地址栏:window.open('地址', 'title', 'location=1, height=200, width=500')
  只显示状态栏:window.open('地址', 'title', 'status=1')
  只显示工具栏:window.open('地址', 'title', 'toolbar=1')
  只显示菜单栏:window.open('地址', 'title', 'menubar=1')
  一个不少:window.open('地址', 'title)
  光棍但可以调整大小:window.open('地址', 'title', 'resizable=1')
去掉所有空格:
  Object.replace(/^\s+|\s+$/g, "")
屏蔽鼠标:
  ncontextmenu="window.event.returnValue=false"
取消选取:
  nselectstart="return false"
不允许粘贴:
  npaste="return false"
关闭输入法:
  <input style="ime-mode:disabled">
不允许另存为:
  <noscript><iframe. src=*.html></iframe></noscript>
得到上一页来源:
  document.referrer
弹出窗口总在最上:
  <body >
弹出确认对话框:
  comfirm('文本')"
  <script>if(confirm('文本')){//确定}else{//取消}
回车转换Tab键:
  if(window.event.keyCode==13){event.keyCode=9}
返回上一页:
  history.go(-1)
重新加载页面:
  window.location.reload()
子页面中调父页面中的方法:
  window.opener.function()
子页面中访问父页面中名为name的控件值:
  window.opener.name.value
子页面中访问父页面中表单中名为name的控件值:
  window.opener.formName.nam.value
得到控件的绝对位置:
  function getIE() {
var t = e.offsetTop;
var l = e.offsetLeft;
while (e = e.offsetParent) {
t += e.offsetTop;
l += e.offsetLeft;
}
alert("top=" + t + " and left=" + l);
}
光标停在文本框文字的最后:
  function toEnd() {
var e = event.srcElement;
var r = e.createTextRange();
r.moveStart("character", e.value.length);
r.collapse(true);
r.select();