IE提示缺少对象?

wangluojianke 2012-03-08 03:04:22
求救!!!
我在网上下了一段js的代码 复制到html页面上是可以正常运行的 但是复制到aspx页面上就会提示缺少对象?为什么呢?
...全文
432 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
wangluojianke 2012-03-08
  • 打赏
  • 举报
回复
终于解决了!谢谢啊!可以买单了
孟子E章 2012-03-08
  • 打赏
  • 举报
回复
下面的的代码ie8ie9都是可以的
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv='Content-Type' content='text/html; charset=gb2312'>
<title>这是一个可以用鼠标随意拖动图标的小程序</title>
</head>
<body onload="init()">
<style type="text/css">
#plane1
{
position: absolute;
left: 290;
top: 170;
width: 121;
z-index: 0;
}

#plane2
{
position: absolute;
left: 400;
top: 250;
width: 118;
z-index: 0;
}
</style>
<script language="JavaScript">
var isNav, isIE
isIE = window.navigator.userAgent.indexOf("MSIE") > 0;
isNav = !isIE

function setZIndex(obj, zOrder) {
obj.zIndex = zOrder
}

// Position an object at a specific pixel coordinate

function shiftTo(obj, x, y) {

if (isNav) {

obj.moveTo(x, y)

} else {

obj.pixelLeft = x

obj.pixelTop = y

}

}

// ***End API Functions***



// Global holds reference to selected element

var selectedObj

// Globals hold location of click relative to element

var offsetX, offsetY



// Find out which element has been clicked on

function setSelectedElem(evt) {

if (isNav) {

// declare local var for use in upcoming loop

var testObj

// make copies of event coords for use in upcoming loop

var clickX = evt.pageX

var clickY = evt.pageY

// loop through all layers (starting with frontmost layer)

// to find if the event coordinates are in the layer

for (var i = document.layers.length - 1; i >= 0; i--) {

testObj = document.layers[i]

if ((clickX > testObj.left) &&

(clickX < testObj.left + testObj.clip.width) &&

(clickY > testObj.top) &&

(clickY < testObj.top + testObj.clip.height)) {

// if so, then set the global to the layer, bring it

// forward, and get outa here

selectedObj = testObj

setZIndex(selectedObj, 100)

return

}

}

} else {

// use IE event model to get the targeted element

var imgObj = window.event.srcElement

// make sure it's one of our planes

if (imgObj.parentElement.id.indexOf("plane") != -1) {

// then set the global to the style property of the element,

// bring it forward, and say adios

selectedObj = imgObj.parentElement.style

setZIndex(selectedObj, 100)

return

}

}

// the user probably clicked on the background

selectedObj = null

return

}

// Drag an element

function dragIt(evt) {

// operate only if a plane is selected

if (selectedObj) {

if (isNav) {

shiftTo(selectedObj, (evt.pageX - offsetX), (evt.pageY - offsetY))

} else {

shiftTo(selectedObj, (window.event.clientX - offsetX), (window.event.clientY - offsetY))

// prevent further system response to dragging in IE

return false

}

}

}

// Set globals to connect with selected element

function engage(evt) {

setSelectedElem(evt)

if (selectedObj) {

// set globals that remember where the click is in relation to the

// top left corner of the element so we can keep the element-to-cursor

// relationship constant throughout the drag

if (isNav) {

offsetX = evt.pageX - selectedObj.left

offsetY = evt.pageY - selectedObj.top

} else {

offsetX = window.event.offsetX

offsetY = window.event.offsetY

}

}

// block mouseDown event from forcing Mac to display

// contextual menu.

return false

}

// Restore elements and globals to initial values

function release(evt) {

if (selectedObj) {

setZIndex(selectedObj, 0)

selectedObj = null

}

}

// Turn on event capture for Navigator

function setNavEventCapture() {

if (isNav) {

document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP)

}

}

// Assign event handlers used by both Navigator and IE (called by onLoad)

function init() {

if (isNav) {

setNavEventCapture()

}

// assign functions to each of the events (works for both Navigator and IE)

document.onmousedown = engage

document.onmousemove = dragIt

document.onmouseup = release

}

</script>
<div id="plane1">
<img name="planePic1" src="http://www.webasp.net/images/logo.gif" border="0" style="cursor: move"></div>
<div id="plane2">
<img name="planePic1" src="http://www.webasp.net/images/logo.gif" border="0" style="cursor: move"></div>
</body>
</html>
孟子E章 2012-03-08
  • 打赏
  • 举报
回复

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
影响的,你可以删除aspx里面的这个
tan598121925 2012-03-08
  • 打赏
  • 举报
回复
有可能,换个浏览器看看[Quote=引用 5 楼 wangluojianke 的回复:]

我基本是整个复制的 还是不行 是不是IE8不兼容?
[/Quote]
wangluojianke 2012-03-08
  • 打赏
  • 举报
回复
我基本是整个复制的 还是不行 是不是IE8不兼容?
wangluojianke 2012-03-08
  • 打赏
  • 举报
回复
<HTML>
<HEAD>
<META http-equiv='Content-Type' content='text/html; charset=gb2312'>
<TITLE>这是一个可以用鼠标随意拖动图标的小程序</TITLE>
</HEAD>
<BODY onLoad="init()">

<style type="text/css">

#plane1 {position:absolute; left:290; top:170; width:121; z-index:0}

#plane2 {position:absolute; left:400; top:250; width:118; z-index:0}

</style>
<script language="JavaScript">

//Modified by the CoffeeCup HTML Editor++

// Global variables for platform branching

var isNav, isIE

if (parseInt(navigator.appVersion) >= 4) {

if (navigator.appName == "Netscape") {

isNav = true

} else {

isIE = true

}

}



// ***Begin CSS custom API Functions***

// Set zIndex property

function setZIndex(obj, zOrder) {

obj.zIndex = zOrder

}

// Position an object at a specific pixel coordinate

function shiftTo(obj, x, y) {

if (isNav) {

obj.moveTo(x,y)

} else {

obj.pixelLeft = x

obj.pixelTop = y

}

}

// ***End API Functions***



// Global holds reference to selected element

var selectedObj

// Globals hold location of click relative to element

var offsetX, offsetY



// Find out which element has been clicked on

function setSelectedElem(evt) {

if (isNav) {

// declare local var for use in upcoming loop

var testObj

// make copies of event coords for use in upcoming loop

var clickX = evt.pageX

var clickY = evt.pageY

// loop through all layers (starting with frontmost layer)

// to find if the event coordinates are in the layer

for (var i = document.layers.length - 1; i >= 0; i--) {

testObj = document.layers[i]

if ((clickX > testObj.left) &&

(clickX < testObj.left + testObj.clip.width) &&

(clickY > testObj.top) &&

(clickY < testObj.top + testObj.clip.height)) {

// if so, then set the global to the layer, bring it

// forward, and get outa here

selectedObj = testObj

setZIndex(selectedObj, 100)

return

}

}

} else {

// use IE event model to get the targeted element

var imgObj = window.event.srcElement

// make sure it's one of our planes

if (imgObj.parentElement.id.indexOf("plane") != -1) {

// then set the global to the style property of the element,

// bring it forward, and say adios

selectedObj = imgObj.parentElement.style

setZIndex(selectedObj,100)

return

}

}

// the user probably clicked on the background

selectedObj = null

return

}

// Drag an element

function dragIt(evt) {

// operate only if a plane is selected

if (selectedObj) {

if (isNav) {

shiftTo(selectedObj, (evt.pageX - offsetX), (evt.pageY - offsetY))

} else {

shiftTo(selectedObj, (window.event.clientX - offsetX), (window.event.clientY - offsetY))

// prevent further system response to dragging in IE

return false

}

}

}

// Set globals to connect with selected element

function engage(evt) {

setSelectedElem(evt)

if (selectedObj) {

// set globals that remember where the click is in relation to the

// top left corner of the element so we can keep the element-to-cursor

// relationship constant throughout the drag

if (isNav) {

offsetX = evt.pageX - selectedObj.left

offsetY = evt.pageY - selectedObj.top

} else {

offsetX = window.event.offsetX

offsetY = window.event.offsetY

}

}

// block mouseDown event from forcing Mac to display

// contextual menu.

return false

}

// Restore elements and globals to initial values

function release(evt) {

if (selectedObj) {

setZIndex(selectedObj, 0)

selectedObj = null

}

}

// Turn on event capture for Navigator

function setNavEventCapture() {

if (isNav) {

document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP)

}

}

// Assign event handlers used by both Navigator and IE (called by onLoad)

function init() {

if (isNav) {

setNavEventCapture()

}

// assign functions to each of the events (works for both Navigator and IE)

document.onmousedown = engage

document.onmousemove = dragIt

document.onmouseup = release

}

</script>
<div id=plane1><img name="planePic1" src="http://www.webasp.net/images/logo.gif" border=0 style="cursor:move"></div>
<div id=plane2><img name="planePic1" src="http://www.webasp.net/images/logo.gif" border=0 style="cursor:move"></div>

</BODY></HTML>
寒似火 2012-03-08
  • 打赏
  • 举报
回复
楼主 自己再好好调试下吧 建议把代码贴出来~~
魏飞翔 2012-03-08
  • 打赏
  • 举报
回复
代码贴出来
tan598121925 2012-03-08
  • 打赏
  • 举报
回复
少了什么没有复制过去吧,对比一下就知道了

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧