ข้ามไปที่เนื้อหาหลัก

การคำนวนค่าความต้านทานแบบต่ออนุกรม




<!DOCTYPE html>
<html>
<head>
<title>การหาค่าความต้านทานแบบอนุกรม</title>
<meta charset="utf-8">
<script src="../js/jquery.min.js"></script>
<script>
var arr_resistance = [];
var resistance = '';

function display_input(max_fields){
var x = 1; //initlal text box count
$('#show_input').html('');
for(var i = x; i <= max_fields; i++) {
$('#show_input').append('<div>R'+i+' : <input type="text" class="input_resistance"/> โอห์ม</div>'); //add input box
if(resistance != ''){
resistance += ' + ';
}
resistance += 'R'+i;
}
$('#show_button').html('<div id="btn_nextstep"><button onclick="step1()">ขั้นตอนต่อไป (1)</button></div>'); //add input box
}

function check_data(){
var msg = "";
$( ".input_resistance" ).each(function(index) {
if($(this).val() == ""){
msg += "- ค่า R" + (index+1) + "\n";
}
});
if(msg == ""){
return true;
}else{
msg = "กรุณากรอกข้อมูลให้ครบถ้วน\n" + msg;
alert(msg);
return false;
}
}

function step1(){
if( check_data() == true){
$('#show_input').append('<br/><div><u>สูตรการคำนวณ การต่อตัวต้านทานแบบอนุกรม</u></div>');
$('#show_input').append('<div><b>RT = '+ resistance +'</b> </div>');
$('#show_button').html('<div id="btn_nextstep"><button onclick="step2()">ขั้นตอนต่อไป (2)</button></div>');
}
}

function step2(){
var input_resistance = '';
$( ".input_resistance" ).each(function() {
if(input_resistance != ''){
input_resistance += " + ";
}
input_resistance += $( this ).val();
arr_resistance.push($( this ).val());
});
$('#show_input').append('<div><b>RT = '+ input_resistance +'</b> </div>');
$('#show_button').html('<div id="btn_nextstep"><button onclick="process()">ดูผลลัพธ์</button></div>');
}

function process() {
myTotal = 0;
for(var i = 0, len = arr_resistance.length; i < len; i++) {
myTotal += parseFloat(arr_resistance[i]);
}
document.getElementById("result").innerHTML = '<b>ค่าความต้านทานรวม = ' + myTotal + ' โอห์ม</b>' ;
}
</script>

</head>
<body>

<p>การคำนวณค่าความต้านทานแบบต่ออนุกรม</p>

<h3>RT = R1 + R2.....+Rn</h3>

<div>
จำนวนตัวต้านทาน : <input type="text" id="qty" onkeyup="display_input(this.value)" /> ตัว
</div>

<p id="show_input"></p>
<p id="result"></p>
<p id="show_button"></p>

</body>
</html>

ความคิดเห็น

โพสต์ยอดนิยมจากบล็อกนี้

แจกฟรี!! ระบบต่างๆที่พัฒนาด้วย PHP สำหรับนำไปใช้ในงานต่างๆ

       สำหรับหลายท่านที่ขอโค้ดเข้ามาทาง Inbox ของเฟซบุ๊กแฟนเพจ หรือถามถึงระบบต่างๆหลังไมค์มานั้น ส่วนใหญ่ก็มีแจกอยู่แล้วในเว็บบอร์ด ThaiCreate.Com นะครับ และด้านล่างนี้ก็เป็นระบบต่างๆที่แจกให้นำไปลองใช้ลองศึกษากันครับ

สอนเขียน PHP แสดงการจองห้องประชุมแบบไฮไลท์ตามช่วงเวลา (แบบเชื่อมต่อฐานข้อมูล MySQL)

ตัวอย่าง ผลลัพธ์ที่ได้จากการจองในฐานข้อมูล ตาราง tb_room สร้างตารางรายชื่อห้องประชุม สำหรับ id นั้นเป็น Primarykey จะกำหนดให้สร้างอัตโนมัติ ทุกครั้งที่เราเพิ่มชื่อห้องประชุมใหม่ -- -- Database: `tobedev_example` -- -- -------------------------------------------------------- -- -- Table structure for table `tb_room` -- CREATE TABLE IF NOT EXISTS `tb_room` (   `id` int(11) NOT NULL,   `name` varchar(30) NOT NULL ) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8; -- -- Dumping data for table `tb_room` -- INSERT INTO `tb_room` (`id`, `name`) VALUES (1, 'ห้องประชุม 1'), (2, 'ห้องประชุม 2'), (3, 'ห้องประชุม 3'), (4, 'ห้องประชุม 4'), (5, 'ห้องประชุม 5'); -- -- Indexes for dumped tables -- -- -- Indexes for table `tb_room` -- ALTER TABLE `tb_room`   ADD PRIMARY KEY (`id`); -- -- AUTO_INCREMENT for dumped tables -- -- -- AUTO_INCREMENT for table `tb_room` -- ALTER TABLE `tb_room`   MODIFY `i...

PHP กับการคิดส่วนลดเป็นเปอร์เซ็น 5%, 10%, 20% ตามช่วงราคาที่กำหนด

<?php     $total_price = 1000;     $discount = 0;         if($total_price >= 500 && $total_price < 1001){         $discount = 5;     }elseif($total_price >= 1001 && $total_price <= 5000){         $discount = 10;     }elseif($total_price >= 5001){         $discount = 20;     }         $discount_bath = ($total_price*$discount)/100; ?> <pre> ซื้อสินค้าครบ 0 ถึง 499 บาท ไม่ได้ส่วนลด ซื้อสินค้าครบ 500 ถึง 1000 บาท ได้ส่วนลด 5% ซื้อสินค้าครบ 1001 ถึง 5000บาท ได้ส่วนลด 10% ซื้อสินค้าครบ 5001 บาทขึ้นไป ได้ส่วนลด 20% </pre> <h3>รวมราคาสินค้า = <?php echo number_format($total_price,2);?></h3> <h5>ส่วนลด = <?php echo $discount;?>%  (<?php echo $discount_bath;?...