常用的javascript语句集
最短的拖动代码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<script language="JavaScript" type="text/javascript">
var x,y
var drag_=false
var D=new Function('obj','return document.getElementById(obj);')
var IE=new Function('','if(navigator.appName.indexOf("Explorer")>=0)return 1;if(navigator.appName.indexOf("Netscape")>=0)return 2')
function Move_obj(obj){//1
D(obj).onmousedown=function(e){drag_=true//4
with(this){style.position="absolute";temp1=offsetLeft;temp2=offsetTop;//5
if(IE()==1){x=event.clientX;y=event.clientY//6
document.onmousemove=function(e){//7
if(drag_==false)return false
with(this){style.left=temp1+event
相关文档:
html:
<div id="slide-box">
<div id="slide">
<div id="fbshutter" style="width:1px;">
<img id="bPic" src="images/01.gif" /> </div>
  ......
关于This
1. 它是一个关键字,并不是变量名或属性名。
2. 它实际指function所关联的对象,如果function没有关联任何对象,则this是Global对象
var msg = 'I am global';
function showMsg(){
alert(this.msg);
};
function nestedShowMsg (){
var nested = function(){
alert(this.msg);
};
nested();
......
1. document.write( " "); 输出语句
2.JS中的注释为//
3.传统的HTML文档顺序是:document- >html- >(head,body)
4.一个浏览器窗口中的DOM顺序是:window- >(navigator,screen,history,location,document)
5.得到表单中元素的名称和值:document.getElementById( "表单中元素的ID號 ").name(或valu ......
原文:刘武|Javascript怎么在两个窗体之间传值
众所周知window.open() 函数可以用来打开一个新窗口,那么如何在子窗体中向父窗体传值呢,其实通过window.opener即可获取父窗体的引用。
如我们新建窗体FatherPage.htm:
XML-Code:
<script type="text/javascript">
function OpenChildWindow()
{ ......