|
 |
|
ขอปรึกษาเรื่องการเขียน jQuery keyup หน่อยครับ มี code จากตัวอย่างกระทู้อื่นครับ |
|
 |
|
|
 |
 |
|
ทำไมไม่ถามเจ้าของโค้ดล่ะครับว่าดัดแปลงยังไง 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
$(document).ready(function(){
var num1 = 0 ,num2 = 0;
var result;
$("input.number").keyup(function(){
num1 = $(this).val();
if($(this).prev().is("input:text.number")){
num2 = $(this).prev().val();
result = $(this).next();
}else{
num2 = $(this).next().val();
result = $(this).next().next();
}
result.val( (parseFloat(num1) / parseFloat(num2)) );
//$(this).parent().next().find("input.linetotal").val( parseFloat(allowance) * parseFloat(bonus) );
});
});
</script>
<form method="post" action="">
<table>
<tr>
<td>
รับค่าที่1 <input type="text" name="a" class="number" />
รับค่าที่ 2 <input type="text" name="b" class="number" />
คำนวณ <input type="text" name="c" class="result" /> %
</td>
</tr>
<tr>
<td>
รับค่าที่1 <input type="text" name="a" class="number" />
รับค่าที่ 2 <input type="text" name="b" class="number" />
คำนวณ <input type="text" name="c" class="result" /> %
</td>
</tr>
</form>
|
 |
 |
 |
 |
Date :
2014-02-18 16:42:28 |
By :
sakuraei |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณครับ แบบนี้ใช่เลย
แต่ถ้าเป็นเปอร์เซ็นปรับอีกหน่อย
เผื่อผู้ที่ยังไม่ค่อยเป็น jQuery เช่นเดียวกัน
Code (PHP)
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script src="http://code.jquery.com/jquery-latest.js"></script>
<form method="post" action="">
รับค่าที่1 <input type="text" name="a" class="cal">
รับค่าที่ 2 <input type="text" name="b" class="cal">
คำนวณ <input type="text" name="c"> %
</form>
<script type="text/javascript">
$(document).ready(function(){
$("input.cal").keyup(function(){
var val_a = $("input[name=a]").val();
var val_b = $("input[name=b]").val();
var val_c = (val_b * 100)/val_a;
$("input[name=c]").val(val_c);
});
});
</script>
|
 |
 |
 |
 |
Date :
2014-02-18 16:43:33 |
By :
iieszz |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ถามเรื่องหารนี่น่า ทำไมเราทำบวกไปให้เนี่ย ฮ่าๆ 
|
 |
 |
 |
 |
Date :
2014-02-18 17:08:46 |
By :
zankumuro |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 00
|