1
我做的網頁。在那裏有一個包含一些產品的下拉菜單,當我們選擇一個項目時,它將在下面顯示一個動態刪除按鈕。我的問題是,產品刪除正確,但具有產品ID爲5的產品未被刪除?有什麼問題?下面是我的代碼
<script type="text/javascript>
function validate(frm_name){
var hiddenFeild = document.getElementById('product');
var addedItems = hiddenFeild.value;
var brokenItems = addedItems.split(",");
if(isEmpty(hiddenFeild.value)){
alert("No Product Added.");
return false;
}
if(brokenItems.length < 3){
alert("Please Add One More Product.");
return false;
}
return true;
}
function removeme(id){
compareDiv = document.getElementById('compare_product');
var remDiv = document.getElementById(id);
compareDiv.removeChild(remDiv);
var hiddenFeild = document.getElementById('product');
var addedItems = hiddenFeild.value;
var brokenItems = addedItems.split(",");
hiddenFeild.value = '';
for(var i = 0 ; i < brokenItems.length-1; i++){
if(brokenItems[i] != id){
hiddenFeild.value = hiddenFeild.value +brokenItems[i]+',';
}
}
}
function selectProduct(){
var flag = 0;
compareDiv = document.getElementById('compare_product');
var proValue = document.getElementById('frm_product').value;
if(proValue != 0){
var product = proValue.split("productvalue");
var productid = product[0];
var productname = product[1];
var hiddenFeild = document.getElementById('product');
var addedItems = hiddenFeild.value;
var brokenItems = addedItems.split(",");
for(var i = 0 ; i < brokenItems.length; i++){
if(brokenItems[i] == productid){
flag = 1;
alert('Already Added');
}
}
if(flag == 0){
hiddenFeild.value = hiddenFeild.value +productid+',';
compareDiv.innerHTML = compareDiv.innerHTML + '<div id="'+productid+'" style="height:30px;"><div style="float:left;" id="added_product">'+productname+'</div><div style="float:right;"><input onClick="removeme('+productid+');" id="remove" name="remove" type="button" value="remove" /></div></div>';
}
}
}
</script>
這個文件是怎麼樣的? – Gumbo 2009-08-14 11:42:19
儘量只發布相關代碼 – 2009-08-14 14:20:54
這很有趣,我媽媽在我年輕時對我說了同樣的話。 – 2009-08-14 16:19:17