in IE.
DragZoomUtil.style([G.mapCover, G.cornerTopDiv, G.cornerRigh
tD iv, G.cornerBottomDiv, G.cornerLef
tD iv],
{top: '0px', left: '0px', width: G.mapWidth + 'px', height: G.mapHeight +'px'});
};
//初始化style
DragZoomControl.
prototype .initStyles_ = function(){
var G = this.globals;
DragZoomUtil.style([G.mapCover, G.cornerTopDiv, G.cornerRigh
tD iv, G.cornerBottomDiv, G.cornerLef
tD iv],
{filter: G.style.alphaIE, opacity: G.style.opacity, background:G.style.fillColor});
G.outlineDiv.style.border = G.style.border;
};
//框选button的click事件
DragZoomControl.
prototype .buttonclick_ = function(){
var G = this.globals;
G.backButtonDiv.style.display='none';
if (G.mapCover.style.display == 'block') { // reset if clicked before dragging
this.rese
tD ragZoom_();
if (G.options.backButtonEnabled) {
this.restoreBackContext_(); // pop the backStack on a button reset
if (G.backStack.length==0) G.backButtonDiv.style.display='none';
}
} else {
this.initCover_();
if ( G.options.backButtonEnabled ) this.saveBackContext_(G.options.backButtonHTML,false); // save the map context for back button
}
};
//后退按钮的click事件
DragZoomControl.
prototype .backbuttonclick_ = function(){
var G = this.globals;
if (G.options.backButtonEnabled && G.backStack.length > 0) {
this.restoreBackContext_();
// invoke the callback if provided
if (G.callbacks['backbuttonclick'] != null) {
G.callbacks.backbuttonclick(G.methodCall);
}
}
};
//后退保存功能
DragZoomControl.
prototype .saveBackContext_ = function(text,methodCall) {
var G = this.globals;
var backFrame = {};
backFrame["center"] = G.map.getCenter();
backFrame["zoom"] = G.map.getZoom();
backFrame["maptype"] = G.map.getCurrentMapType();
backFrame["text"] = G.backButtonDiv.innerHTML; // this saves the previous button text
backFrame["methodCall"] = methodCall; //This determines if it was an internal or method call
G.backStack.push(backFrame);
G.backButtonDiv.innerHTML = text;
// Back Button is turned on in rese
tD ragZoom_()
};
//后退功能
DragZoomControl.
prototype .restoreBackContext_ = function() {
var G = this.globals;
var backFrame = G.backStack.pop();
G.map.setCenter(backFrame["center"],backFrame["zoom"],backFrame["maptype"]);
G.backButtonDiv.innerHTML = backFrame["text"];
G.methodCall = backFrame["methodCall"];
if (G.backStack.length==0) G.backButtonDiv.style.display = 'none'; // if we're at the top of the stack, hide the back botton
};
//在地图上显示叠加层
DragZoomControl.
prototype .initCover_ = function(){
var G = this.globals;
G.mapPosition = DragZoomUtil.getElementPosition(G.map.getContainer());
this.se
tD imensions_();
this.setButtonMode_('zooming');
DragZoomUtil.style([G.mapCover], {display: 'block', background: G.style.fillColor});
DragZoomUtil.style([G.outlineDiv], {width: '0px', height: '0px'});
//invoke callback if provided
if(G.callbacks['buttonclick'] != null){
G.callbacks.buttonclick();
}
};
//获得鼠标的坐标
DragZoomControl.
prototype .getRelPos_ = function(e) {
var pos = DragZoomUtil.getMousePosition(e);
var G = this.globals;
return {top: (pos.top - G.mapPosition.top),
left: (pos.left - G.mapPosition.left)};
};
//当用户拉框时求的矩形
DragZoomControl.
prototype .getRectangle_=function(startX,startY,pos,ratio){
var left=false;
var top=false;
var dX=pos.left-startX;
var dY=pos.top-startY;
if(dX<0){
dX=dX*-1;
top=true;
}
delta=dX>dY?dX:dY;
return{
startX:startX,
startY:startY,
endX:startX+delta,
endY:startY+parseInt(delta*ratio),
width:delta,
height:parseInt(delta*ratio),
left:left,
top:top
}
};
//重置Buttonde的CSS
DragZoomControl.
prototype .rese
tD ragZoom_=function(){
var G=this.globals;
DragZoomUtil.style([G.mapCover,G.cornerTopDiv,G.cornerRigh
tD iv,G.cornerBottomDiv,G.cornerLef
tD iv],
{display:'none',opacity:G.style.opacity,fillter:G.style.alphaIE});
G.outlineDiv.style.display='none';
this.setButtonMode_('normal');
if(G.options.backButtonEnabled && (G.backStack.length>0))G.backButtonDiv.style.display='block';
};
var DragZoomUtil={};
//根据ID取得元素
DragZoomUtil.gE=function(sId){
return document.getElementById(sId);
};
//取得DOM元素的绝对位置
DragZoomUtil.getMousePosition=function(e){
var posX=0;
var posY=0;
if(!e)var e=window.event;
if(e.pageX||e.pageY){
posX=e.pageX;
posY=e.pageY;
}else if(e.clientX||e.clientY){
posX=e.clientX+(document.documentElement.scrollLeft?document.documentElement.scrollLeft:document.body.scrollLeft);
posY=e.clientY+(document.documentElement.scrollTop?document.documentElement.scrollTop:document.body.scrollTop);
}
return {left:posX,top:posY};
};
//取得某一DOM元素的位置
DragZoomUtil.getElementPosition=function(element){
var leftPos=element.offsetLeft;
var topPos=element.offsetTop;
var parElement=element.offsetParent;
while(parElement!=null){
leftPos+=parElement.offsetLeft;
topPos+=parElement.offsetTop;
parElement=parElement.offsetParent;
}
return{left:leftPos,top:topPos};
};
//将style应用于DOM元素
DragZoomUtil.style=function(elements,styles){
if(typeof(elements)=='string'){
eiements=DragZoomUtil.getManyElements(elements);
}
for(var i=0;i
";
for(var i=0;i
"+point.toString()+" ");
//(address"go ");
}//for
}//if
else{
document.getElementById("divOutput").innerHTML=result.Status.code;
}//else
}
/**
* 这个例子演示了 Google Map API 的以下功能:
* * 可拖拽的标注
* * 在地图上覆盖折线
* * 计算地理距离
* * 事件处理(单击、拖拽)
* * 消息提示窗口(气泡窗口)
* * 利用链表维护各种对象
* * 自定义控件
*
* 注意:为了在 IE6 中正常显示折线,必须在网页的 标签中加上:
*
*
* @author haogang
*/
/**
* 本示例用一个双向链表维护用户设定的标注,能够容易的实现标注的遍历和删除
* 每个链表结点 m 有如下字段:
* m.prev 前驱标注
* m.next 后继标注
* m.segPrev 连接本标注与前驱标注的线段
* m.segNext 连接本标注与后继标注的线段
*/
function GRulerControl() {
var me = this;
// 可国际化的字符串
me.RESET_BUTTON_TITLE_ = '清除所有测距标注';
me.ENABLE_BUTTON_TITLE_ = '添加测距标注已启用,单击这里禁用';
me.DISABLE_BUTTON_TITLE_ = '添加测距标注已禁用,单击这里启用';
me.DELETE_BUTTON_TITLE_ = '删除';
me.RESET_BUTTON_IMAGE_ = 'images/ruler_clear.png';
me.ENABLE_BUTTON_IMAGE_ = 'images/ruler_enabled.png';
me.DISABLE_BUTTON_IMAGE_ = 'images/ruler_disabled.png';
me.BACKGROUND_IMAGE_ = 'images/ruler_background.png'
me.KILOMETER_ = '公里';
me.METER_ = '米';
}
GRulerControl.prototype = new GControl();
/**
* 初始化标尺控件
*/
GRulerControl.prototype .initialize = function(map) {
var me = this;
var container = document.createElement('div');
/**
*默认位置在右上角
*/
GRulerControl.prototype .getD efaultPosition = function() {
return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(8, 30));
}
me.setButtonStyle_(container);
// “启用/禁用”按钮
var btnEnable = document.createElement('img');
btnEnable.width = btnEnable.height = 20;
GEvent.addDomListener(btnEnable, 'click',
function() {
me.setEnabled(!me.isEnabled());
}
);
container.appendChild(btnEnable);
// “重置”按钮
var btnReset = document.createElement('img');
btnReset.width = btnReset.height = 20;
btnReset.src = me.RESET_BUTTON_IMAGE_;
btnReset.title = me.RESET_BUTTON_TITLE_;
GEvent.addDomListener(btnReset, 'click',
function() {
me.reset();
}
);
container.appendChild(btnReset);
// 距离标签
var txtInfo = document.createElement('div');
txtInfo.style.font = 'small Arial';
txtInfo.style.fontWeight = 'bold';
txtInfo.style.fontSize = '9pt';
txtInfo.style.width = "82px";
container.appendChild(txtInfo);
// 初始化内部变量
map.rulerControl_ = me;
me.map_ = map;
me.head_ = new Object();
me.tail_ = new Object();
me.head_.next_ = me.tail_;
me.tail_.prev_ = me.head_;
me.btnEnable_ = btnEnable;
me.btnReset_ = btnReset;
me.txtInfo_ = txtInfo;
me.setEnabled(true);
map.getContainer().appendChild(container);
return container;
}
/**
* 设置控件的格式
*/
GRulerControl.prototype .setButtonStyle_ = function(button) {
button.style.backgroundImage = 'url(' + this.BACKGROUND_IMAGE_ + ')';
button.style.font = "small Arial";
button.style.border = "1px solid #888888";
button.style.padding = "4px";
button.style.textAlign = "right";
button.style.cursor = "pointer";
}
/**
* 用恰当的格式表示距离
*/
GRulerControl.prototype .formatD istance_ = function(len) {
var me = this;
len = Math.round(len);
if (len <= 1000) {
return len + ' ' + me.METER_;
} else if (len <= 1000000) {
return len / 1000 + ' ' + me.KILOMETER_;
}
return Math.round(len / 1000) + ' ' + me.KILOMETER_;
}
/**
* 格式化角度为字符串
*/
GRulerControl.prototype .formatD egree_ = function(value) {
value = Math.abs(value);
var v1 = Math.floor(value);
var v2 = Math.floor((value - v1) * 60);
var v3 = Math.round((value - v1) * 3600 % 60);
return v1 + '°' + v2 + '\'' + v3 + '"';
}
/**
* 格式化经纬度为字符串
*/
GRulerControl.prototype .formatLatLng_ = function(pt) {
var me = this;
var latName, lngName;
var lat = pt.lat();
var lng = pt.lng();
latName = lat >= 0 ? '北纬' : '南纬';
lngName = lng >= 0 ? '东经' : '西经';
return lngName + me.formatD egree_(lng) + ','
+ latName + me.formatD egree_(lat);
}
/**
* 返回控件的默认位置
*/
GRulerControl.prototype .getD efaultPosition = function() {
return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(8, 8));
}
/**
* 返回控件是否已启用
*/
GRulerControl.prototype .isEnabled = function() {
return this.enabled_;
}
/**
* 设置控件的“启用/禁用"状态
*/
GRulerControl.prototype .setEnabled = function(value) {
var me = this;
if (value == me.enabled_)
return;
me.enabled_ = value;
if (me.enabled_) {
me.mapClickHandle_ = GEvent.addListener(me.map_, 'click', me.onMapClick_);
me.txtInfo_.style.display = 'block';
me.btnReset_.style.display = 'inline';
me.btnEnable_.src = me.ENABLE_BUTTON_IMAGE_;
me.btnEnable_.title = me.ENABLE_BUTTON_TITLE_;
me.updateDistance_();
} else {
GEvent.removeListener(me.mapClickHandle_);
me.txtInfo_.style.display = 'none';
me.btnReset_.style.display = 'none';
me.btnEnable_.src = me.DISABLE_BUTTON_IMAGE_;
me.btnEnable_.title = me.DISABLE_BUTTON_TITLE_;
}
}
/**
* 事件处理函数:当用户单击地图时,要在该位置添加一个标注
*/
GRulerControl.prototype .onMapClick_ = function(marker, point) {
var me = this.rulerControl_;
// 如果用户单击的是标注,不再这里处理
if (marker)
return;
// 创建标注,并添加到链表中
var newMarker = new GMarker(point, {draggable: true});
var pos = me.tail_.prev_;
newMarker.prev_ = pos;
newMarker.next_ = pos.next_;
pos.next_.prev_ = newMarker;
pos.next_ = newMarker;
// 为标注添加事件处理函数:拖拽标注时要更新连接线段和距离
GEvent.addListener(newMarker, 'dragend',
function() {
me.map_.closeInfoWindow();
me.updateSegments_(newMarker);
me.updateDistance_();
}
);
// 为标注添加事件处理函数:单击标注时要显示气泡窗口
GEvent.addListener(newMarker, 'click',
function() {
newMarker.openInfoWindow(me.createInfoWindow_(newMarker));
}
);
// 将创建的标注添加到地图中
me.map_.addOverlay(newMarker);
if (newMarker.prev_ != me.head_) {
// 如果这不是第一个标注,则创建连接到上一个标注的线段,并显示在地图中
var segment = [newMarker.prev_.getPoint(), point];
newMarker.segPrev_ = new GPolyline(segment);
newMarker.prev_.segNext_ = newMarker.segPrev_;
me.map_.addOverlay(newMarker.segPrev_);
// 更新距离显示
me.updateDistance_();
}
}
/**
* 统计总距离,并显示在网页中
*/
GRulerControl.prototype .updateDistance_ = function() {
var me = this;
var len = me.getD istance();
// 结果显示在网页中
me.txtInfo_.innerHTML = me.formatD istance_(len);
}
/**
* 遍历链表,统计总距离
*/
GRulerControl.prototype .getD istance = function() {
var me = this;
var len = 0;
// 周游链表,累计相邻两个标注间的距离
for (var m = me.head_; m != me.tail_; m = m.next_) {
if (m.prev_ && m.prev_.getPoint)
len += m.prev_.getPoint().distanceFrom(m.getPoint());
}
return len;
}
/**
* 清除所有标注,初始化链表
*/
GRulerControl.prototype .reset = function() {
var me = this;
for (var m = me.head_.next_; m != me.tail_; m = m.next_) {
me.map_.removeOverlay(m);
if (m.segNext_)
me.map_.removeOverlay(m.segNext_);
}
me.head_ = new Object();
me.tail_ = new Object();
me.head_.next_ = me.tail_;
me.tail_.prev_ = me.head_;
me.updateDistance_();
}
/**
* 事件处理函数:当用户拖拽标注、标注坐标改变时被调用,这里要更新与该标注连接的线段
* @param {GMarker} marker 被拖拽的标注
*/
GRulerControl.prototype .updateSegments_ = function(marker) {
var me = this;
var segment;
// 更新连接前驱的线段
if (marker.segPrev_ && marker.prev_.getPoint) {
// 从地图上删除旧的线段
me.map_.removeOverlay(marker.segPrev_);
// 根据标注的当前坐标构造新的线段,并更新链表结点的相关字段
segment = [marker.prev_.getPoint(), marker.getPoint()];
marker.segPrev_ = new GPolyline(segment);
marker.prev_.segNext_ = marker.segPrev_;
// 将新线段添加到地图中
me.map_.addOverlay(marker.segPrev_);
}
// 更新连接后继的线段,与上类似
if (marker.segNext_ && marker.next_.getPoint) {
me.map_.removeOverlay(marker.segNext_);
segment = [marker.getPoint(), marker.next_.getPoint()];
marker.segNext_ = new GPolyline(segment);
marker.next_.segPrev_ = marker.segNext_;
me.map_.addOverlay(marker.segNext_);
}
}
/**
* 为气泡提示窗口创建 DOM 对象,包括标注的坐标和“删除”按钮
* @param {GMarker} marker 对应的标注
*/
GRulerControl.prototype .createInfoWindow_ = function(marker) {
var me = this;
// 为气泡提示窗口创建动态 DOM 对象,这里我们用 DIV 标签
var div = document.createElement('div');
div.style.fontSize = '10.5pt';
div.style.width = '250px';
div.appendChild(
document.createTextNode(me.formatLatLng_(marker.getPoint())));
var hr = document.createElement('hr');
hr.style.border = 'solid 1px #cccccc';
div.appendChild(hr);
// 创建“删除”按钮
var lnk = document.createElement('div');
lnk.innerHTML = me.DELETE_BUTTON_TITLE_;
lnk.style.color = '#0000cc';
lnk.style.cursor = 'pointer';
lnk.style.textD ecoration = 'underline';
// 为“删除”按钮添加事件处理:调用 removePoint() 并重新计算距离
lnk.onclick =
function() {
me.map_.closeInfoWindow();
me.removePoint_(marker);
me.updateDistance_();
};
div.appendChild(lnk);
// 当用户关闭气泡时 Google Map API 会自动释放该对象
return div;
}
/**
* 事件处理函数:当用户选择删除标注时被调用,这里要删除与该标注连接的线段
* @param {GMarker} marker 要删除的标注
*/
GRulerControl.prototype .removePoint_ = function(marker) {
var me = this;
// 先从地图上删除该标注
me.map_.removeOverlay(marker);
// 对于中间结点,还要把它的前驱和后继用线段连接起来
if (marker.prev_.getPoint && marker.next_.getPoint) {
var segment = [marker.prev_.getPoint(), marker.next_.getPoint()];
var polyline = new GPolyline(segment);
marker.prev_.segNext_ = polyline;
marker.next_.segPrev_ = polyline;
me.map_.addOverlay(polyline);
}
marker.prev_.next_ = marker.next_;
marker.next_.prev_ = marker.prev_;
if (marker.segPrev_)
me.map_.removeOverlay(marker.segPrev_);
if (marker.segNext_)
me.map_.removeOverlay(marker.segNext_);
}
function load(){
//检查浏览器的兼容性
if(GBrowserIsCompatible()){
//加载地图
map=new GMap2(document.getElementById("map_canvas"));
//设置地图的中心坐标
var center=new GLatLng(24.49933,118.13800);
map.setCenter(center,12);
//设置地图的缩放工具
map.setUIToDefault();
//添加缩略图
map.addControl(new GOverviewMapControl());
//激活地图的双击放大功能和支持滑轮缩放
map.enableDoubleClickZoom();
map.enableScrollWheelZoom();
//给地图添加右键菜单
createContextMenu(map);
//位于左上角
var topLeft=new GControlPosition(G_ANCHOR_TOP_LEFT,new GSize(0,0));
//添加地址导航控件
map.addControl(new GNavLabelControl(),topLeft);
//添加自定义的控件
map.addControl(new GRulerControl());
//定义一个框选缩放控件样式
var styleOpts={};
//定义框选控件的参数
var otherOpts={};
//设置按钮的名称
otherOpts.buttonHTML='框选缩放';
//设置点击后的名称
otherOpts.buttonZoomingHTML='请在地图上拉一个框';
//支持连续框选缩放
otherOpts.stickyZoomEnabled=true;
//设置拉框清除的时间间隔
otherOpts.overlayRemoveTime=60;
//拉框时地图的透明度,取值 从0~1
styleOpts.opacity=0;
//支持右键啦框缩小地图
otherOpts.rightMouseZoomOutEnabled=true;
var zcontrol=new DragZoomControl(styleOpts,otherOpts,{});
//位于左下角
var bottomLeft=new GControlPosition(G_ANCHOR_BOTTOM_LEFT,new GSize(0,0));
//添加自定义的控件
map.addControl(zcontrol,bottomLeft);
//初始化GClientGeocoder对象
GoogleGeocoder=new GClientGeocoder();
var icon=new GIcon();
html='这是什么
';
icon.image="http://labs.google.com/ridefinder/images/mm_20_red.png";
icon.iconSize=new GSize(21,29);
var marker=createMarker(point,icon,html);
var point=marker.getPoint(112.429714,39.934522);
map.addOverlay(marker);
geocoder=new GClientGeocoder();
var marker=new GMarker(center,{draggable:true});
map.addOverlay(marker);
document.getElementById("lat").innerHTML=center.lat().toFixed(5);
document.getElementById("lng").innerHTML=center.lng().toFixed(5);
GEvent.addListener(marker,"dragend",function(){
var point=marker.getPoint();
map.panTo(point);
document.getElementById("lat").innerHTML=point.lat().toFixed(5);
document.getElementById("lng").innerHTML=point.lng().toFixed(5);
});
GEvent.addListener(map,"moveend",function(){
map.clearOverlays();
var center=map.getCenter();
var marker=new GMarker(center,{draggable:true});
map.addOverlay(marker);
document.getElementById("lat").innerHTML=center.lat().toFixed(5);
document.getElementById("lng").innerHTML=center.lng().toFixed(5);
GEvent.addListener(marker,"dragend",function(){
var point=marker.getPoint();
map.panTo(point);
document.getElementById("lat").innerHTML=point.lat().toFixed(5);
document.getElementById("lng").innerHTML=point.lng().toFixed(5);
});
});
}
else
alert("error");
}
//创建右键菜单,参数为地图对象,即为该地图添加右键菜单功能
function createContextMenu(map){
//右键菜单其实是一个DIV
contextmenu=document.createElement("div");
//初始创建时右键菜单不可见
contextmenu.style.visibility="hidden";
//设置右键菜单的背景色及宽度
contextmenu.style.background="#ffffff";
contextmenu.style.border="1px solid #8888FF";
//获取地图对象的容器,并将菜单的DIV添加上去,但此时的菜单中不可见的
map.getContainer().appendChild(contextmenu);
//为地图的右键添加事件侦听。当右键点击地图时,在地图右键点击的地方把菜单显示出来
GEvent.addListener(map,"singlerightclick",function(pixel,title){
//获取右键点击时的坐标位置(指像素)
clickedPixel=pixel;
var x=pixel.x;
var y=pixel.y;
//如果右键点击达到了屏幕的边界,调整菜单的位置
if(x>map.getSize().width-120)
{
x=map.getSize().width-120
}
if(y>map.getSize().height-100)
{
y=map.getSize().height-100
}
//实例化一个地图的位置控件
var pos=new GControlPosition(G_ANCHOR_TOP_LEFT,new GSize(x,y));
//把菜单DIV作为对象传递给地图位置控件
pos.apply(contextmenu);
//把菜单设置为可见
contextmenu.style.visibility="visible";
});
//为地图添加click事件侦听器,当单击地图时,把菜单隐藏
GEvent.addListener(map,"click",function(){
contextmenu.style.visiblity="hidden";
});
}
function createMarker(point,baseIcon,html){
var icon=new GIcon(baseIcon);
var marker=new GMarker(point,icon);
GEvent.addListener(marker,"click",function(){
marker.openInfoWindowHtml(html);
});
return marker;
}
//初始化地图
window.onload=load;
//卸载地图
window.onunload=GUnload;
厦门旅游服务系统
查询地址:
<td >
提示:单击您的当前位置和每个便民设施标注点通过测量距离选择您要的路线
td >
<td >
td >
<td >
td >
<td >
用鼠标拖拉地图中心的红色气球标记就可以显示所在位置的经纬度坐标数据
td >
<td width="50">
纬度:
td >
<td id="lat">td >
<td width="50">
经度:
td >
<td id="lng">td >
Javascript小技巧一箩筐
事件源对象
event.srcElement.tagName
event.srcElement.type
捕获释放 event.srcElement.setCapture();
event.srcElement.releaseCapture();
事件按键
event.keyCode
event.shiftKey
event.altKey
event.ctrlKey
事件返回值
event.returnValue
鼠标位置 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).appendChild(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)
替换CSS
document.all.csss.href = "a.css";
并排显示
display:inline
隐藏焦点 hidefocus=true
根据宽度换行 style="word-break:break-all"
自动刷新
简单邮件
快速转到位置 obj.scrollIntoView(true)
锚
anchors
网页传递参数 location.search();
可编辑 obj.contenteditable=true
执行菜单命令
obj.execCommand
双字节字符
/[^x00-xff]/
汉字
/[u4e00-u9fa5]/
让英文字符串超出表格宽度自动换行
word-wrap: break-word; word-break: break-all;
透明背景
获得style内容 obj.style.cssText
HTML标签
document.documentElement.innerHTML
第一个style标签
document.styleSheets[0]
style标签里的第一个样式
document.styleSheets[0].rules[0]
防止点击空链接时,页面往往重置到页首端。
word
上一网页源
asp:
request.servervariables("HTTP_REFERER")
javascript:
document.referrer
释放内存 CollectGarbage();
禁止右键
document.oncontextmenu = function() { return false;}
禁止保存
禁止粘贴
地址栏图标
favicon.ico 名字最好不变16*16的16色,放虚拟目录根目录下
收藏栏图标
查看源码
关闭输入法
自动全选
ENTER键可以让光标移到下一个输入框
文本框的默认值
title换行 obj.title = "123
sdfs "
获得时间所代表的微秒 var n1 = new Date("2004-10-10".replace(/-/g, "/")).getTime()
窗口是否关闭 win.closed
checkbox扁平
获取选中内容 document.selection.createRange().duplicate().text
自动完成功能
打开该功能
关闭该功能
窗口最大化
无关闭按钮IE window.open("aa.htm", "meizz", "fullscreen=7");
统一编码/解码 alert(decodeURIComponent(encodeURIComponent("http://你好.com?as= hehe")))
encodeURIComponent对":"、"/"、";" 和 "?"也编码
表格行指示
//各种尺寸
s += " 网页可见区域宽:"+ document.body.clientWidth;
s += " 网页可见区域高:"+ document.body.clientHeight;
s += " 网页可见区域高:"+ document.body.offsetWeight +" (包括边线的宽)";
s += " 网页可见区域高:"+ document.body.offsetHeight +" (包括边线的宽)";
s += " 网页正文全文宽:"+ document.body.scrollWidth;
s += " 网页正文全文高:"+ document.body.scrollHeight;
s += " 网页被卷去的高:"+ document.body.scrollTop;
s += " 网页被卷去的左:"+ document.body.scrollLeft;
s += " 网页正文部分上:"+ window.screenTop;
s += " 网页正文部分左:"+ window.screenLeft;
s += " 屏幕分辨率的高:"+ window.screen.height;
s += " 屏幕分辨率的宽:"+ window.screen.width;
s += " 屏幕可用工作区高度:"+ window.screen.availHeight;
s += " 屏幕可用工作区宽度:"+ window.screen.availWidth;
//过滤数字
//特殊用途
//不缓存
//正则匹配匹配中文字符的正则表达式: [u4e00-u9fa5]
匹配双字节字符(包括汉字在内):[^x00-xff]
匹配空行的正则表达式: [s| ]*
匹配HTML标记的正则表达式:/<(.*)>.*1>|<(.*) />/
匹配首尾空格的正则表达式:(^s*)|(s*$)(像vbscript那样的trim函数)
匹配Email地址的正则表达式:w+([-+.]w+)*@w+([-.]w+)*.w+([-.]w+)*
匹配网址URL的正则表达式:http://([w-]+.)+[w-]+(/[w- ./?%&=]*)?
以下是例子:
利用正则表达式限制网页表单里的文本框输入内容:
用正则表达式限制只能输入中文:onkeyup="value=value.replace(/[^u4E00-u9FA5]/g,"")" onbeforepaste="clipboardData.setD ata("text",clipboardData.getD ata("text").replace(/[^u4E00-u9FA5]/g,""))"
1.用正则表达式限制只能输入全角字符: onkeyup="value=value.replace(/[^uFF00-uFFFF]/g,"")" onbeforepaste="clipboardData.setD ata("text",clipboardData.getD ata("text").replace(/[^uFF00-uFFFF]/g,""))"
2.用正则表达式限制只能输入数字:onkeyup="value=value.replace(/[^d]/g,"") "onbeforepaste="clipboardData.setD ata("text",clipboardData.getD ata("text").replace(/[^d]/g,""))"
3.用正则表达式限制只能输入数字和英文:onkeyup="value=value.replace(/[W]/g,"") "onbeforepaste="clipboardData.setD ata("text",clipboardData.getD ata("text").replace(/[^d]/g,""))"
//消除图像工具栏
or
//无提示关闭
function Close()
{
var ua=navigator.userAgent
var ie=navigator.appName=="Microsoft Internet Explorer"?true:false
if(ie)
{
var IEversion=parseFloat(ua.substring(ua.indexOf("MSIE ")+5,ua.indexOf(";",ua.indexOf("MSIE "))))
if(IEversion< 5.5)
{
var str = ""
str += " ";
document.body.insertAdjacentHTML("beforeEnd", str);
document.all.noTipClose.Click();
}
else
{
window.opener =null;
window.close();
}
}
else
{
window.close()
}
}
//取得控件得绝对位置(1)
<script language="javascript">
function getoffset(e)
{
var t=e.offsetTop;
var l=e.offsetLeft;
while(e=e.offsetParent)
{
t+=e.offsetTop;
l+=e.offsetLeft;
}
var rec = new Array(1);
rec[0] = t;
rec[1] = l;
return rec
}
//光标停在文字最后
<script language="javascript">
function cc()
{
var e = event.srcElement;
var r =e.createTextRange();
r.moveStart("character",e.value.length);
r.collapse(true);
r.select();
}
//页面进入和退出的特效
进入页面
推出页面
这个是页面被载入和调出时的一些特效。duration表示特效的持续时间,以秒为单位。transition表示使
用哪种特效,取值 为1-23:
0 矩形缩小
1 矩形扩大
2 圆形缩小
3 圆形扩大
4 下到上刷新
5 上到下刷新
6 左到右刷新
7 右到左刷新
8 竖百叶窗
9 横百叶窗
10 错位横百叶窗
11 错位竖百叶窗
12 点扩散
13 左右到中间刷新
14 中间到左右刷新
15 中间到上下
16 上下到中间
17 右下到左上
18 右上到左下
19 左上到右下
20 左下到右上
21 横条
22 竖条
23
//网页是否被检索
其中属性值有以下一些:
属性值为"all": 文件将被检索,且页上链接可被查询;
属性值为"none": 文件不被检索,而且不查询页上的链接;
属性值为"index": 文件将被检索;
属性值为"follow": 查询页上的链接;
属性值为"noindex": 文件不检索,但可被查询链接;
属性值为"nofollow":
//打印分页
page1
page2
//设置打印
<script language=javascript>
function window.onload()
{
// -- advanced features
factory.printing.SetMarginMeasure(2) // measure margins in inches
factory.printing.SetPageRange(false, 1, 3) // need pages from 1 to 3
factory.printing.printer = "HP DeskJet 870C"
factory.printing.copies = 2
factory.printing.collate = true
factory.printing.paperSize = "A4"
factory.printing.paperSource = "Manual feed"
// -- basic features
factory.printing.header = "居左显示&b居中显示&b居右显示页码,第&p页/共&P页"
factory.printing.footer = "(自定义页脚)"
factory.printing.portrait = false
factory.printing.leftMargin = 0.75
factory.printing.topMargin = 1.5
factory.printing.rightMargin = 0.75
factory.printing.bottomMargin = 1.5
}
function Print(frame) {
factory.printing.Print(true, frame) // print with prompt
}
具体使用手册,更多信息,点这里
//自带的打印预览
WebBrowser.ExecWB(1,1) 打开
Web.ExecWB(2,1) 关闭现在所有的IE窗口,并打开一个新窗口
Web.ExecWB(4,1) 保存网页
Web.ExecWB(6,1) 打印
Web.ExecWB(7,1) 打印预览
Web.ExecWB(8,1) 打印页面设置
Web.ExecWB(10,1) 查看页面属性
Web.ExecWB(15,1) 好像是撤销,有待确认
Web.ExecWB(17,1) 全选
Web.ExecWB(22,1) 刷新
Web.ExecWB(45,1) 关闭窗体无提示
//去掉打印时的页眉页脚
<script language="JavaScript">
var HKEY_Root,HKEY_Path,HKEY_Key;
HKEY_Root="HKEY_CURRENT_USER";
HKEY_Path="\Software\Microsoft\Internet Explorer\PageSetup\";
//设置网页打印的页眉页脚为空
function PageSetup_Null()
{
try
{
var Wsh=new ActiveXObject("WScript.Shell");
HKEY_Key="header";
Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"");
HKEY_Key="footer";
Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"");
}
catch(e){}
}
//设置网页打印的页眉页脚为默认值
function PageSetup_Default()
{
try
{
var Wsh=new ActiveXObject("WScript.Shell");
HKEY_Key="header";
Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"&w&b页码,&p/&P");
HKEY_Key="footer";
Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"&u&b&d");
}
catch(e){}
}
//浏览器验证
function checkBrowser()
{
this.ver=navigator.appVersion
this.dom=document.getElementById?1:0
this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom)?1:0;
this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom)?1:0;
this.ie4=(document.all && !this.dom)?1:0;
this.ns5=(this.dom && parseInt(this.ver) >= 5) ?1:0;
this.ns4=(document.layers && !this.dom)?1:0;
this.mac=(this.ver.indexOf("Mac") > -1) ?1:0;
this.ope=(navigator.userAgent.indexOf("Opera")>-1);
this.ie=(this.ie6 || this.ie5 || this.ie4)
this.ns=(this.ns4 || this.ns5)
this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns5 || this.ns4 || this.mac || this.ope)
this.nbw=(!this.bw)
return this;
}
//计算内容宽和高
//无模式的提示框
function modelessAlert(Msg)
{
window.showModelessDialog("javascript:alert(""+escape(Msg)+"");window.close();","","status:no;resizable:no;help:no;dialogHeight:height:30px;dialogHeight:40px;");
}
//屏蔽按键
屏蔽鼠标右键、Ctrl+N、Shift+F10、Alt+F4、F11、F5刷新、退格键
<script language="Javascript">
//可编辑SELECT
11111111
222222
333333
//设置光标位置
function getCaret(textbox)
{
var control = document.activeElement;
textbox.focus();
var rang = document.selection.createRange();
rang.setEndPoint("StartToStart",textbox.createTextRange())
control.focus();
return rang.text.length;
}
function setCaret(textbox,pos)
{
try
{
var r =textbox.createTextRange();
r.moveStart("character",pos);
r.collapse(true);
r.select();
}
catch(e)
{}
}
function selectLength(textbox,start,len)
{
try
{
var r =textbox.createTextRange();
r.moveEnd("character",len-(textbox.value.length-start));
r.moveStart("character",start);
r.select();
}
catch(e)
{//alert(e.description)}
}
function insertAtCaret(textbox,text)
{
textbox.focus();
document.selection.createRange().text = text;
}
//页内查找
function findInPage(str)
{
var txt, i, found,n = 0;
if (str == "")
{
return false;
}
txt = document.body.createTextRange();
for (i = 0; i <= n && (found = txt.findText(str)) != false; i++)
{
txt.moveStart("character", 1);
txt.moveEnd("textedit");
}
if (found)
{
txt.moveStart("character", -1);
txt.findText(str);
txt.select();
txt.scrollIntoView();
n++;
}
else
{
if (n > 0)
{
n = 0;
findInPage(str);
}
else
{
alert(str + "... 您要找的文字不存在。 请试着输入页面中的关键字再次查找!");
}
}
return false;
}
//书
http://www.itpub.net/attachment.php?s=&postid=1894598
http://www.wrclub.net/down/listd own.aspx?id=1341//操作EXECL
<script language="javascript">
function jS tartExcel() {
var xls = new ActiveXObject ( "Excel.Application" );
xls.visible = true;
var newBook = xls.Workbooks.Add;
newBook.Worksheets.Add;
newBook.Worksheets(1).Activate;
xls.ActiveWorkBook.ActiveSheet.PageSetup.Orientation = 2;
xls.ActiveWorkBook.ActiveSheet.PageSetup.PaperSize = 5;
newBook.Worksheets(1).Columns("A").columnwidth=50;
newBook.Worksheets(1).Columns("A").WrapText = true;
newBook.Worksheets(1).Columns("B").columnwidth=50;
newBook.Worksheets(1).Columns("B").WrapText = true;
newBook.Worksheets(1).Range("A1:B1000").NumberFormat = "0";
newBook.Worksheets(1).Range("A1:B1000").HorizontalAlignment = -4131;
newBook.Worksheets(1).Cells(1,1).Interior.ColorIndex="15";
newBook.Worksheets(1).Cells(1,1).value="First Column, First Cell";
newBook.Worksheets(1).Cells(2,1).value="First Column, Second Cell";
newBook.Worksheets(1).Cells(1,2).value="Second Column, First Cell";
newBook.Worksheets(1).Cells(2,2).value="Second Column, Second Cell";
newBook.Worksheets(1).Name="My First WorkSheet";
}
tip
<script Language="JavaScript">
//***********默认设置定义.*********************
tPopWait=50;//停留tWait豪秒后显示提示。
tPopShow=5000;//显示tShow豪秒后关闭提示
showPopStep=20;
popOpacity=99;
//***************内部变量定义*****************
sPop=null;
curShow=null;
tFadeOut=null;
tFadeIn=null;
tFadeWaiting=null;
document.write("");
document.write("
");
function showPopupText(){
var o=event.srcElement;
MouseX=event.x;
MouseY=event.y;
if(o.alt!=null && o.alt!=""){o.dypop=o.alt;o.alt=""};
if(o.title!=null && o.title!=""){o.dypop=o.title;o.title=""};
if(o.dypop!=sPop) {
sPop=o.dypop;
clearTimeout(curShow);
clearTimeout(tFadeOut);
clearTimeout(tFadeIn);
clearTimeout(tFadeWaiting);
if(sPop==null || sPop=="") {
dypopLayer.innerHTML="";
dypopLayer.style.filter="Alpha()";
dypopLayer.filters.Alpha.opacity=0;
}
else {
if(o.dyclass!=null) popStyle=o.dyclass
else popStyle="cPopText";
curShow=setTimeout("showIt()",tPopWait);
}
}
}
function showIt(){
dypopLayer.className=popStyle;
dypopLayer.innerHTML=sPop;
popWidth=dypopLayer.clientWidth;
popHeight=dypopLayer.clientHeight;
if(MouseX+12+popWidth>document.body.clientWidth) popLeftAdjust=-popWidth-24
else popLeftAdjust=0;
if(MouseY+12+popHeight>document.body.clientHeight) popTopAdjust=-popHeight-24
else popTopAdjust=0;
dypopLayer.style.left=MouseX+12+document.body.scrollLeft+popLeftAdjust;
dypopLayer.style.top=MouseY+12+document.body.scrollTop+popTopAdjust;
dypopLayer.style.filter="Alpha(Opacity=0)";
fadeOut();
}
function fadeOut(){
if(dypopLayer.filters.Alpha.opacity0) {
dypopLayer.filters.Alpha.opacity-=1;
tFadeIn=setTimeout("fadeIn()",1);
}
}
document.onmouseover=showPopupText;
插入文字");
}
}
//netscapte下操作xml
doc = new ActiveXObject("Msxml2.DOMDocument");
doc = new ActiveXObject("Microsoft.XMLDOM")
->>
doc = (new DOMParser()).parseFromString(sXML,"text/xml")
//判断键值
<script language="javascript">
var ie =navigator.appName=="Microsoft Internet Explorer"?true:false;
function keyDown(e)
{
if(!ie)
{
var nkey=e.which;
var iekey="现在是ns浏览器";
var realkey=String.fromCharCode(e.which);
}
if(ie)
{
var iekey=event.keyCode;
var nkey="现在是ie浏览器";
var realkey=String.fromCharCode(event.keyCode);
if(event.keyCode==32){realkey="" 空格""}
if(event.keyCode==13){realkey="" 回车""}
if(event.keyCode==27){realkey="" Esc""}
if(event.keyCode==16){realkey="" Shift""}
if(event.keyCode==17){realkey="" Ctrl""}
if(event.keyCode==18){realkey="" Alt""}
}
alert("ns浏览器中键值:"+nkey+" "+"ie浏览器中键值:"+iekey+" "+"实际键为"+realkey);
}
document.onkeydown = keyDown;
//Javascript Document.
请按任意一个键。。。。
//禁止FSO
1.注销组件
regsvr32 /u scrrun.dll
2.修改PROGID
HKEY_CLASSES_ROOTScripting.FileSystemObject
Scripting.FileSystemObject
3.对于使用object的用户,修改HKEY_CLASSES_ROOTScripting.
//省略号
就是比如有一行文字,很长,表格内一行显示不下.
//检测media play版本
//图象按比例
<script language="JavaScript">
//细线SELECT
function getComputerName()
{
var objWMIService = GetObject("Winmgmts:rootcimv2");
for(e = new Enumerator(objWMIService) ; !e.atEnd() ; e.moveNext())
{
var getComputer = e.item();
return getComputer.Name;
}
}
//条件编译
<script language=javascript>
/*@cc_on @*/
/*@if (@_win32 && @_js cript_version>5)
function window.confirm(str)
{
execScript("n = msgbox(""+ str +"", 257)", "vbscript");
return(n == 1);
}
@end @*/
//mergeAttributes 复制所有读/写标签属性到指定元素。
This is a sample DIV element.
This is another sample DIV element.
以上内容可以随意转载,转载后请注名来源和出处!
原文链接:http://ttyp.cnblogs.com/archive/2004/11/15/63900.aspx
1111
11111111111111
111111111
//Import
function Import() {
for( var i=0; ijs$/i))
document.write("<script type="text/javascript" src="" + file + "">");
else
document.write("");
}
};
//js 枚举
function getComputerName()
{
var objWMIService = GetObject("Winmgmts:rootcimv2");
for(e = new Enumerator(objWMIService) ; !e.atEnd() ; e.moveNext())
{
var getComputer = e.item();
return getComputer.Name;
}
}
//条件编译
<script language=javascript>
/*@cc_on @*/
/*@if (@_win32 && @_js cript_version>5)
function window.confirm(str)
{
execScript("n = msgbox(""+ str +"", 257)", "vbscript");
return(n == 1);
}
@end @*/
//mergeAttributes 复制所有读/写标签属性到指定元素。
This is a sample DIV element.
This is another sample DIV element.
电子书制作:源码爱好者