ตัวเลือก image
ตัวเลือก :image เลือกองค์ประกอบที่มี
ประเภท image ซึ่งเป็นรูปภาพ
สำหรับส่งแบบฟอร์ม
คำสั่งที่เทียบเท่ากับ $(':image') คือ
$('[type=image]')
เนื่องจาก :image ไม่ได้อยู่ในข้อกำหนด CSS
เพื่อประสิทธิภาพที่ดีกว่าในเบราว์เซอร์สมัยใหม่
ควรใช้ [type='image'] แทน
ไวยากรณ์
นี่คือวิธีการเลือกองค์ประกอบประเภท image:
$(':image');
ตัวอย่าง
มาทำการเลือกอินพุตทั้งหมดที่มีประเภท image และ
กำหนดพื้นหลังสีเขียวและขอบสีแดงให้กับพวกมันโดยใช้เมธอด
css:
<form>
<input type="button" value="button">
<input type="file">
<input type="password">
<button>button</button>
<input type="reset">
<input type="radio" name="test">
<input type="radio" name="test">
<input type="checkbox">
<input type="image">
<input type="text">
</form>
$('input:image').css({background: 'green', border: '2px red solid'});
$('form').submit(function(event) {
event.preventDefault(); // ป้องกันการส่งแบบฟอร์ม
});