我目前正在开放购物车框架工作。在那个Open Cart中,动态表单存在。在那个Dynamic表单中,所以脚本也是动态的,我必须在表单数据发生变化时进行计算。在此期间我遇到了一些问题。我正在动态地选择框选项值....
foreach ($options as $option) { $initiates_f=$initiates_f+1; ?>
<?php if ($option['type'] == 'select'){ ?>
var a_<?php echo $initiates_f;?>= document.getElementById("option[<?php echo $option['product_option_id']; ?>]").value;
var spl_<?php echo $initiates_f;?> = a_<?php echo $initiates_f;?>.split("_");
var cr_<?php echo $initiates_f;?> = spl_<?php echo $initiates_f;?>[1];
var operator3_<?php echo $initiates_f;?> = cr_<?php echo $initiates_f;?>.split("[");
var symbol<?php echo $initiates_f;?> = operator3_<?php echo $initiates_f;?>[0];
var dtt_<?php echo $initiates_f;?> = operator3_<?php echo $initiates_f;?>[1];
var myarr_<?php echo $initiates_f;?> = dtt_<?php echo $initiates_f;?>.split("$");
var symbol_st_<?php echo $initiates_f;?> = myarr_<?php echo $initiates_f;?>[1];
var split_value_<?php echo $initiates_f;?> = myarr_<?php echo $initiates_f;?>[1];
var final_value_<?php echo $initiates_f;?> =symbol_st_<?php echo $initiates_f;?>.split(".");
var Final_price<?php echo $initiates_f;?> =final_value_<?php echo $initiates_f;?>[0];
<?php } } ?>
此外,我将Final_price值分配给for循环外的某个变量。这个脚本编码...
var total_amount=0;
for(var i=1; i<=j; i++)
{alert('test');
final_prices=("Final_price"+i).value;
alert(final_prices);
alert(symbol_prices.value);*/
if(isNumber(final_prices)){
alert("number");
/*if(symbol_prices =='+') {
alert("plus");
var total_amount+=parseInt(original_prices)+parseInt(final_prices);
calculated_price_element.innerHTML=total_amount;
alert(total_amount);
} else if(symbol_prices =='-') {
alert("minus");
var total_amount+=parseInt(original_prices)-parseInt(final_prices);
calculated_price_element.innerHTML=total_amount;
alert(total_amount);
}*/
//alert('test');
}
}
因为编码final_prices=("Final_price"+i).value;
没有从指定的变量返回值,如何获得此值...请解决它..我正在努力2天..
任何其他替代解决方案......请指导我......
答案 0 :(得分:3)
我得到了解决方案....请按照这个对其他人更有用...... 我用PHP和java脚本结束了......
foreach ($options as $option) { $initiates_f=$initiates_f+1; ?>
<?php if ($option['type'] == 'select'){ ?>
var a_<?php echo $initiates_f;?>= document.getElementById("option[<?php echo $option['product_option_id']; ?>]").value;
var spl_<?php echo $initiates_f;?> = a_<?php echo $initiates_f;?>.split("_");
var cr_<?php echo $initiates_f;?> = spl_<?php echo $initiates_f;?>[1];
var operator3_<?php echo $initiates_f;?> = cr_<?php echo $initiates_f;?>.split("[");
var symbol<?php echo $initiates_f;?> = operator3_<?php echo $initiates_f;?>[0];
var dtt_<?php echo $initiates_f;?> = operator3_<?php echo $initiates_f;?>[1];
var myarr_<?php echo $initiates_f;?> = dtt_<?php echo $initiates_f;?>.split("$");
var symbol_st_<?php echo $initiates_f;?> = myarr_<?php echo $initiates_f;?>[1];
var split_value_<?php echo $initiates_f;?> = myarr_<?php echo $initiates_f;?>[1];
var final_value_<?php echo $initiates_f;?> =symbol_st_<?php echo $initiates_f;?>.split(".");
var Final_price<?php echo $initiates_f;?> =final_value_<?php echo $initiates_f;?>[0];
<?php } }
echo 'var final_prices=0;';
$initiates_f=0;
foreach ($options as $option) { $initiates_f=$initiates_f+1;
if ($option['type'] == 'select')
{
echo 'final_prices=parseInt(Final_price'.$initiates_f.');';
echo "total_amount+=parseInt(final_prices);
// alert(total_amount);
calculated_price_element.innerHTML=total_amount;";
}
}
?>
谢谢你...