329 view
หมวดหมู่ : สำหรับโปรแกรมเมอร์
วันที่สร้าง : 13/06/2017
ยกตัวอย่างเรามี select box ที่มี ID ชื่อ mySelect
เราสามารถ Add ค่า Option ให้กับ select box ด้วย jQuery ตามตัวอย่าง
var output = [];
selectValues = { "1": "test 1", "2": "test 2" };
$(document).ready(function(){
$.each(selectValues, function(key, value) {
output.push('');
});
$('#mySelect').html(output.join(''));
});
ตัวอย่างนี้จะถ่ายค่า option ลงไปใน array ก่อนแล้วค่อยนำมา add เข้าไปใน html ของ combobox อีกที
ถ้าชอบบทความนี้ กด Like เลย :
jQuery วิธี Add option ให้ select box โดยดึงค่าจาก Array
TAGS :
Javascript
Jquery
Programming
โปรแกรมมิ่ง
329 view
หมวดหมู่ : สำหรับโปรแกรมเมอร์
วันที่สร้าง : 13/06/2017