js控制添加删除行,兼容常用浏览器
<DIVclass=name><SPANstyle="COLOR:red">*</SPAN>商品地址1:</DIV><DIVclass="value"id="shangp...
<DIV class=name><SPAN style="COLOR: red">*</SPAN>商品地址1:</DIV><DIV class="value" id="shangpindizhi" style="width:270px; padding-left:0px; ">
<INPUT class=txt id=ProUrl style="WIDTH: 215px;" value=请输入商品网址 name=ProUrl onFocus="if (value==defaultValue)value='http://'" onBlur="if(!value)value=defaultValue"><input type="button" value="+" onclick="javascript:addRemoveItem('add','shangpindizhi');" style="font-size:12px"></DIV>
<DIV class=exp>填写商品地址,限制只能填写6个地址。</DIV>
<script type="text/javascript">
var maxid = 2 ;
function addRemoveItem(act,target){
if ((!act || act == 'add') && target){
var $shangpindizhi = typeof(target) != 'object' ? document.getElementById(target) : target;
if (!$shangpindizhi) return;
if(maxid<="6"){
var obj = document.createElement('<div style="border-bottom:1px #CCC dotted">');
obj.innerHTML = "商品地址"+maxid+":<INPUT class=txt id=ProUrl"+maxid+" style='WIDTH: 215px;' name=ProUrl"+maxid+" value=http://>" + '<input type="button" value="-" onclick="javas'+'cript:addRemoveItem(\'del\',this.parentNode);" style="font-size:12px"/></div>';
$shangpindizhi.appendChild(obj);
obj = $shangpindizhi = null;
maxid++;
}else{
alert('只能添加6个!');
return false;
}
} else if (act == 'del' && target){
if (typeof(target) != 'object') return;
target.parentNode.removeChild(target);
maxid--;
}
}
</script>
这段代码IE可以,如何兼容火狐呀? 展开
<INPUT class=txt id=ProUrl style="WIDTH: 215px;" value=请输入商品网址 name=ProUrl onFocus="if (value==defaultValue)value='http://'" onBlur="if(!value)value=defaultValue"><input type="button" value="+" onclick="javascript:addRemoveItem('add','shangpindizhi');" style="font-size:12px"></DIV>
<DIV class=exp>填写商品地址,限制只能填写6个地址。</DIV>
<script type="text/javascript">
var maxid = 2 ;
function addRemoveItem(act,target){
if ((!act || act == 'add') && target){
var $shangpindizhi = typeof(target) != 'object' ? document.getElementById(target) : target;
if (!$shangpindizhi) return;
if(maxid<="6"){
var obj = document.createElement('<div style="border-bottom:1px #CCC dotted">');
obj.innerHTML = "商品地址"+maxid+":<INPUT class=txt id=ProUrl"+maxid+" style='WIDTH: 215px;' name=ProUrl"+maxid+" value=http://>" + '<input type="button" value="-" onclick="javas'+'cript:addRemoveItem(\'del\',this.parentNode);" style="font-size:12px"/></div>';
$shangpindizhi.appendChild(obj);
obj = $shangpindizhi = null;
maxid++;
}else{
alert('只能添加6个!');
return false;
}
} else if (act == 'del' && target){
if (typeof(target) != 'object') return;
target.parentNode.removeChild(target);
maxid--;
}
}
</script>
这段代码IE可以,如何兼容火狐呀? 展开
- 你的回答被采纳后将获得:
- 系统奖励15(财富值+成长值)+难题奖励10(财富值+成长值)+提问者悬赏20(财富值+成长值)
1个回答
展开全部
onFocus,onBlur,把value改成this.value
var obj = document.createElement('<div style="border-bottom:1px #CCC dotted">');
改成:
var obj = document.createElement('div');
obj.style.borderBottom = "1px #CCC dotted";
var obj = document.createElement('<div style="border-bottom:1px #CCC dotted">');
改成:
var obj = document.createElement('div');
obj.style.borderBottom = "1px #CCC dotted";
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询