1,532   1 ช่วยทีครับ ผมสร้าง ตาราง กรอกข้อมูล แล้วใช้ Jquery ในการแทรกตาราง เพื่อเพิ่ม ช่องในการกรอก ถ้าจะให้แสดงผลไปทั้งตาราง ต้องประกาศตัวแปร อย่างไรครับ



totaesb


พลังงานการช่วยเหลือ
( Level 1 )


คะแนนขอบคุณจากสมาชิก
( 0 )


ตอบกระทู้ ( 0 )
เขียนบทความ ( 0 )

ช่วยทีครับ ผมสร้าง ตาราง กรอกข้อมูล แล้วใช้ Jquery ในการแทรกตาราง เพื่อเพิ่ม ช่องในการกรอก ถ้าจะให้แสดงผลไปทั้งตาราง ต้องประกาศตัวแปร อย่างไรครับ พวก ID กับ NAME ผิดถูกอย่างไร แนะนำด้วยครับ

Code (PHP)
<script src="http://code.jquery.com/jquery-latest.js"></script>

<table id="myTbl" cellpadding="2" cellspacing="2" border="1" width="100%">

<td width="10%"> หัวข้อ </td>
<td width="30%"> จำนวนชั่วโมงตามแผนการสอน </td>
<td width="30%"> จำนวนชั่วโมงที่สอนจริง</td>
<td width="30%"> ระบุเหตุผลที่การสอนจริงต่างจาก แผนการสอนหากมีความแตกต่างเกิน 25% </td>
</tr>

<tr id="firstTr" >
<td><input type="text" id="table[]" name="table[]"></td>
<td><input type="text"id="table1[]" name="table1[]"></td>
<td><input type="text"id="table2[]" name="table2[]"></td>
<td><textarea type="textarea"id="table3[]" name="table3[]"> </textarea></td>
</tr>
</tr>
</table>
<br />
<table width="500" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<button id="addRow" type="button">+</button>
&nbsp;
<button id="removeRow" type="button">-</button>
&nbsp;
&nbsp;
&nbsp;
<button id="Submit" type="submit">Submit</button>
</td>
</tr>
</table>
</form>

<script type="text/javascript">
$(function(){
$("#addRow").click(function(){
$("#myTbl").append($("#firstTr").clone());
});
$("#removeRow").click(function(){
if($("#myTbl tr").size()>2){
$("#myTbl tr:last").remove();
}else{
alert("ต้องมีรายการข้อมูลอย่างน้อย 1 รายการ");
}
});
});
</script>
ความคิดเห็นที่ 1
อ้างอิงความเห็น


bamossza


พลังงานการช่วยเหลือ
( Level 3 )


คะแนนขอบคุณจากสมาชิก
( 16 )


ตอบกระทู้ ( 112 )
เขียนบทความ ( 28 )

จริงแล้วเราสามารถใช้ชื่อเดียวกันได้ครับ เช่น
<input type="text" name="table[]" value="1"/>
<input type="text" name="table[]" value="2"/>
<input type="text" name="table[]" value="3"/>
<input type="text" name="table[]" value="4"/>


ส่วนตรง Jquery
$(function(){
   $('input[name="table[]"]').each(function() {
      var table_value = $(this).val();
      console.log(table_value );
      //Output : 1,2,3,4
   });
});


ลองประยุกต์ดูครับlaughing

แสดงความเห็น

อัพโหลดรูปภาพ..คลิก *** เพื่อความปลอดภัยในด้านสิทธิ ไม่อนุญาติให้นำลิ้งรูปภาพจากที่อื่นมาแปะ ถ้าพบเจอ ลบกระทู้ ทันที ***

Back to Top