作者热门文章
- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我目前从事 Open cart 框架工作。在那个打开的购物车中,存在动态表单。在那个动态表单中,所以脚本也是动态的,我必须计算表单数据何时发生变化。在此期间我遇到了一些问题。我正在动态获取选择框选项值....
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天..任何其他替代解决方案......请指导我......
最佳答案
我得到了解决方案....请遵循它对其他人更有用......我以 php 和 java-script 结束...
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;";
}
}
?>
谢谢你...
关于php - 如何将字符串中的值连接到变量中的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15547615/
我是一名优秀的程序员,十分优秀!