<form method="post" action="obj.php">
<input type="hidden" name="habays" id="habays" value="" />
<div id="objDiv" style="float: left;"></div>
<input type="text" style="width:200px;" name="objIn" id="objIn" value="" />
<input type="button" id="copy" value="添加" />
<input type="submit" value="提交">
</form>
<script type="text/javascript">
var objIn=document.getElementById("objIn");
var objDiv=document.getElementById("objDiv");
var objSave = document.getElementById("habays");
$("#copy").on("click",function(){
objDiv.innerHTML+="<input type='hidden' name='habay[]' value='"+(objIn.value)+"'/><span οnclick='javascript:removeUrl(this)' style='margin-right:10px;'>"+(objIn.value)+"</span>";
objSave.value += objIn.value+',';
$('#objIn').val('');
});
function removeUrl(Obj){
var pUrl = jQuery.trim(jQuery(Obj).text());
jQuery("input[name='habay[]']").each(function(){
if(jQuery(this).val()==pUrl){
jQuery(this).remove();
}
});
Obj.remove();
Array.prototype.remove=function(dx){
if(isNaN(dx)||dx>this.length){return false;}
for(var i=0,n=0;i<this.length;i++){
if(this[i]!=this[dx]){
this[n++]=this[i]
}
}
this.length-=1
}
var saveObj = objSave.value;
var saveObjarr = saveObj.split(",");
var i = 0;
for (var i; i < saveObjarr.length; i++) {
if(saveObjarr[i] == pUrl) {
saveObjarr.remove(i);
}
}
objSave.value = saveObjarr;
}
</script>