js对话框弹出问题 直接alert(obj)就可以了干嘛还要先去ID,再重新通过此ID获得原来的对象呢? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 这个要用事件拦截,修改<a href=''>的默认行为,改为a.href="javascript:addTags(this);"; alert(document.getElementById(aid)); // 这种写法本身就有问题,要获取类型须使用typeof关键字!// 若直接调用时会调用对象自身的toString方法,IE下一般返回[object],而a是个特例,// IE下a被重写了toString方法,返回的是href属性值!因此才会看到javascript:void(0)L@_@K<!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> <title> new document </title> <meta name="generator" content="editplus" /> <meta name="author" content="Gao YiXiang" /> <meta name="email" content="[email protected]" /> <meta name="keywords" content="javascript dhtml dom" /> <meta name="description" content="I love web development." /></head><body> <div id="tagDiv" class=""></div> <script type="text/javascript"> <!--function createTags(){ var li = document.createElement("li"); var a = document.createElement("a"); var len = document.getElementsByTagName("a").length; a.id = "a"+len; a.innerText = "new tag"; // Error! //a.onclick = "addTags(this)"; // Correct! a.ondblclick = function() { removeTags(this); }; a.href = "javascript:void(0)"; li.appendChild(a); document.getElementById("tagDiv").appendChild(li);}function removeTags(obj){ alert(obj.id); alert(typeof obj); var oDiv = document.getElementById("tagDiv"); alert(typeof oDiv);}createTags(); //--> </script></body></html> 考虑到兼容性,更新一下,IE6sp1,FF2测试可用!L@_@K<!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> <title> new document </title> <meta name="generator" content="editplus" /> <meta name="author" content="Gao YiXiang" /> <meta name="email" content="[email protected]" /> <meta name="keywords" content="javascript dhtml dom" /> <meta name="description" content="I love web development." /></head><body> <div id="tagDiv"></div> <script type="text/javascript"> <!--function createTags(){ var li = document.createElement("li"); var a = document.createElement("a"); var len = document.getElementsByTagName("a").length; a.id = "a"+len; a.innerHTML = "new tag"; // innerText 在 FF 下无效! // Error! //a.onclick = "addTags(this)"; // Correct! a.ondblclick = function() { removeTags(this); }; a.href = "javascript:void(0)"; li.appendChild(a); document.getElementById("tagDiv").appendChild(li);}function removeTags(obj){ alert(obj.id); alert(typeof obj); var oDiv = document.getElementById("tagDiv"); alert(typeof oDiv);}createTags(); //--> </script></body></html> frame区域更新问题? 求树一棵 讨教,如何在脚本函数中调用脚本函数? 如何用JS模拟键盘消息 !!!请问VBscript中类似continue的语句是什么?急!!! 快来啊,解决问题的快乐(ActiveXObject) 如何用Javascript脚本清除密码及表单内容(急!!!) 哇,老孟,我真是服了你了 jquery 增加,删除 DIV元素求解 qq怎么做手机端核pc端聊天 弹出提示,为什么没有声音?? 使用链接提交表单-快被firefox折磨死了
// 这种写法本身就有问题,要获取类型须使用typeof关键字!
// 若直接调用时会调用对象自身的toString方法,IE下一般返回[object],而a是个特例,
// IE下a被重写了toString方法,返回的是href属性值!因此才会看到javascript:void(0)L@_@K
<!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>
<title> new document </title>
<meta name="generator" content="editplus" />
<meta name="author" content="Gao YiXiang" />
<meta name="email" content="[email protected]" />
<meta name="keywords" content="javascript dhtml dom" />
<meta name="description" content="I love web development." />
</head>
<body>
<div id="tagDiv" class=""></div>
<script type="text/javascript">
<!--
function createTags()
{
var li = document.createElement("li");
var a = document.createElement("a");
var len = document.getElementsByTagName("a").length;
a.id = "a"+len;
a.innerText = "new tag";
// Error!
//a.onclick = "addTags(this)";
// Correct!
a.ondblclick = function()
{
removeTags(this);
};
a.href = "javascript:void(0)";
li.appendChild(a);
document.getElementById("tagDiv").appendChild(li);
}function removeTags(obj)
{
alert(obj.id);
alert(typeof obj); var oDiv = document.getElementById("tagDiv");
alert(typeof oDiv);
}createTags();
//-->
</script>
</body>
</html>
<!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>
<title> new document </title>
<meta name="generator" content="editplus" />
<meta name="author" content="Gao YiXiang" />
<meta name="email" content="[email protected]" />
<meta name="keywords" content="javascript dhtml dom" />
<meta name="description" content="I love web development." />
</head>
<body>
<div id="tagDiv"></div>
<script type="text/javascript">
<!--
function createTags()
{
var li = document.createElement("li");
var a = document.createElement("a");
var len = document.getElementsByTagName("a").length;
a.id = "a"+len;
a.innerHTML = "new tag"; // innerText 在 FF 下无效!
// Error!
//a.onclick = "addTags(this)";
// Correct!
a.ondblclick = function()
{
removeTags(this);
};
a.href = "javascript:void(0)";
li.appendChild(a);
document.getElementById("tagDiv").appendChild(li);
}function removeTags(obj)
{
alert(obj.id);
alert(typeof obj); var oDiv = document.getElementById("tagDiv");
alert(typeof oDiv);
}createTags();
//-->
</script>
</body>
</html>