日期:2014-05-16 浏览次数:20479 次
<select id="ListBoxRight">
<option value="a">A</option>
<option value="b">B</option>
<option value="c">C</option>
</select>
<input type="text" id="tb_calculation" style="width:60%" /><input type="button" value="验证" onclick="check()"/>
<script>
function check() {
var sel = document.getElementById('ListBoxRight'), txt = document.getElementById('tb_calculation');
var arr = [],rst='';
for (var i = 0; i < sel.options.length; i++) {
arr[i] = "[kpi].[" + sel.options[i].value + "]";
}
switch (txt.value) {
case 'sum([kpi].[all])': rst = arr.join('+'); break;
case 'average([kpi].[all])': rst = arr.length == 1 ? arr[0] : "(" + arr.join('+') + ")/" + arr.length; break;
}
txt.value = rst;
}
</script>