<!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">
<body>
<div id="tip1" style="width:100px;height:100px;border:1px solid red">
<div id="sp" style="height:50px;height:50px;border:1px solid blue"></div>
</div>
<div id="tip2" style="width:100px;height:100px;border:1px solid green"></div>
<script>
document.getElementById("tip1").onclick=function(){
document.getElementById("tip2").innerHTML=document.getElementById("tip1").innerHTML;
document.getElementById("tip1").innerHTML='';
}
document.getElementById("sp").onclick=function(e){
var e=e||window.event;
if (!document.all)
e.stopPropagation()
else
window.event.cancelBubble=true
alert(111);
}
</script>
</body>
</html>看例子,首先点击tip1,
然后sp区域到tip2的内容里,
这时sp点击事件失效了,问如何使sp产生效果
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<div id="tip1" style="width:100px;height:100px;border:1px solid red">
<div id="sp" style="height:50px;height:50px;border:1px solid blue"></div>
</div>
<div id="tip2" style="width:100px;height:100px;border:1px solid green"></div>
<script>
document.getElementById("tip1").onclick=function(){
document.getElementById("tip2").innerHTML=document.getElementById("tip1").innerHTML;
document.getElementById("tip1").innerHTML='';
}
document.getElementById("sp").onclick=function(e){
var e=e||window.event;
if (!document.all)
e.stopPropagation()
else
window.event.cancelBubble=true
alert(111);
}
</script>
</body>
</html>看例子,首先点击tip1,
然后sp区域到tip2的内容里,
这时sp点击事件失效了,问如何使sp产生效果
解决方案 »
- ExtJS 按钮重新渲染的问题
- 请教个问题document.write( "<li>c的值是否是NaN:" + tc + "<br>" ); 这其中的<li>是什么意思啊。?跟<ul>
- window.opener.location.href ie下的跨域问题
- 按钮背景图片问题
- 在Ext里面,怎样通过右键菜单子项获得grid选中行的值。
- 在一个网上考试系统中,能不能控制考生所访问的网页以防作弊?
- 我的菜单为什么遮不住底下的Select?
- 请问<script language="jscript.encode" src="me.jse"></script>这句什么意思?
- javascript应该很容易的
- JQuery mobile popup功能 如何弹出后3秒自动关闭
- 请问怎么获取span标签中的html元素的值?
- scriptx哪几个属性是免费的?怎么安装使用啊?是不是只需要下载那个smsx.cab包就行了?
<head>
<title></title>
</head>
<body>
<div id="tip1" style="width:100px;height:100px;border:1px solid red">
<div id="sp" style="height:50px;height:50px;border:1px solid blue"></div>
</div>
<div id="tip2" style="width:100px;height:100px;border:1px solid green"></div>
<script type="text/javascript">
var sp = document.getElementById("sp");
var tip1 = document.getElementById("tip1");
var tip2 = document.getElementById("tip2");
sp.onclick = function (e) {
var e = e || window.event;
if (!document.all) e.stopPropagation()
else window.event.cancelBubble = true
alert(111);
};
tip1.onclick = function () {
this.removeChild(sp);
tip2.appendChild(sp);
};
</script>
</body>使用操作jQuery对象引用的方法:
<head>
<title></title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$('#sp').click(function (e) {
var e = e || window.event;
if (!document.all) e.stopPropagation()
else window.event.cancelBubble = true
alert(111);
});
$('#tip1').click(function () {
$(this).children().prependTo($('#tip2'));
});
});
</script>
</head>
<body>
<div id="tip1" style="width:100px;height:100px;border:1px solid red">
<div id="sp" style="height:50px;height:50px;border:1px solid blue"></div>
</div>
<div id="tip2" style="width:100px;height:100px;border:1px solid green"></div>
</body>如果使用live绑定,根据id判断,事情会变得非常复杂,一方面tip1要把自己的内容赋给tip2,还要清空自己,很快会发现产生非常多的副效果,冒泡什么的处理也麻烦起来了。
<head>
<title></title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$('#sp').live('click', function (e) {
//...
alert(111);
});
$('#tip1').click(function () {
$('#tip2').html(this.innerHTML);
$(this).html('');
});
});
</script>
</head>
<body>
<div id="tip1" style="width:100px;height:100px;border:1px solid red">
<div id="sp" style="height:50px;height:50px;border:1px solid blue"></div>
</div>
<div id="tip2" style="width:100px;height:100px;border:1px solid green"></div>
</body>