|
|
|
รบกวนช่วยอธิบายการทำงานของโค๊ดตัวนี้ให้ผมหน่อยได้ไหมครับ ไม่ทราบว่าการทำงานเป็นยังไง |
|
|
|
|
|
|
|
Code (PHP)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="th" xml:lang="th">
<head>
<meta http-equiv="content-type" content="text/html; charset=tis-620" />
<title>calculate number</title>
<script type="text/javascript">
//<![CDATA[
window.onload=function(){
var f = document.getElementById('box');
function calA(i){
var d = function (){
var k = f['k[]'][i];
var p = f['p[]'][i];
var a = f['a[]'][i];
k.value = k.value.replace(/[^\d\.]/g,'');
p.value = p.value.replace(/[^\d\.]/g,'');
a.value = (k.value*1) * (p.value*1);
if (a.value <= 0){
a.style.color = 'red';
} else {
a.style.color = 'black';
}
}
return d;
}
for(var i=0;i<f['k[]'].length;i++){
f['k[]'][i].onkeyup = calA(i);
f['p[]'][i].onkeyup = calA(i);
}
}
function calSum(){
var f = document.getElementById('box');
function calA(i){
var d = function (){
var k = f['k[]'][i];
var p = f['p[]'][i];
var a = f['a[]'][i];
var t = f['t'];
var sum = 0;
/*
for(var i=0;i<f['a[]'].length;i++){
sum += a.value;
}
*/
t.value = "sum";
//k.value = k.value.replace(/[^\d\.]/g,'');
//p.value = p.value.replace(/[^\d\.]/g,'');
//a.value = (k.value*1) * (p.value*1);
if (t.value <= 0){
t.style.color = 'red';
} else {
t.style.color = 'black';
}
}
return d;
}
for(var i=0;i<f['k[]'].length;i++){
f['k[]'][i].onkeyup = calA(i);
f['p[]'][i].onkeyup = calA(i);
}
}
//]]>
</script>
</head>
<body>
<form method="post" action="?" id="box">
<input type="text" name="a" value="k" disabled="disabled" />
<input type="text" name="p" value="p" disabled="disabled" />
<input type="text" name="k" value="a" disabled="disabled" />
<?php echo '<br'.' />';?>
<?php foreach(range(1,5) as $m):?>
<input type="text" name="k[]" value="" onKeyUp="JavaScript:calSum();" />
<input type="text" name="p[]" value="" onKeyUp="JavaScript:calSum();"/>
<input type="text" name="a[]" value="" />
<?php echo '<br'.' />';?>
<?php endforeach;?>
<br/>
<input type="text" name="t" value="" />
</form>
</body>
</html>
อันนี้ผมลองทำดูครับ แต่ก็ไม่ประสบผลสำเร็จ ไม่สามารถทำงานได้ function calSum()
|
|
|
|
|
Date :
2013-01-24 23:52:37 |
By :
nook563 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|