javascript实现爱你在FF IE下都有效的添加一个项目
IE不是很乖,在IE里setAttribute只认一些静态属性,而像ONCLICK事件时无效的,要用attchEvent方法
无标题文档
var elementCount=0;
function mycreateElement(element,tag)
{
elementCount++;
var parentElement=element;
var count=elementCount;
var childElement=document.createElement(tag);
setProperty(childElement,"type","text");
setProperty(childElement,"id","input" + elementCount)
var delElement=document.createElement("input");
setProperty(delElement,"type","button");
setProperty(delElement,"value","删除");
setProperty(delElement,"id","delButton" + elementCount)
if(navigator.appName=="Microsoft Internet Explorer")
delElement.attachEvent("onclick",function(){del(count)})
else
setProperty(delElement,"onclick","del(" + elementCount + ")");
var wrap=document.createElement('div')
setProperty(wrap,"id","div" + elementCount)
wrap.appendChild(childElement);
wrap.appendChild(delElement);
parentElement.appendChild(wrap)
}
function setProperty(element,tag,property)
{
var element1=element;
element1.setAttribute(tag,property);
}
function del(elementCount1)
{
var parentNode=document.getElementById("mycontent");
var divNode=document.getElementById("div" +elementCount1);
parentNode.removeChild(divNode);
}
[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]