การเรียกใช้งาน Selectors ของ jQuery ในการอ้างถึง element ต่าง ๆ (text Selector()

หมวดสำหรับแบ่งบันความ รู้ต่างๆ จะมีหมวดย่อยๆ ในหมวดนี้ เช่น php, SQL, XML, CSS

Moderator: mindphp, ผู้ดูแลกระดาน

M008
PHP Hero Member
PHP Hero Member
โพสต์: 109
ลงทะเบียนเมื่อ: 03/05/2013 10:44 am

การเรียกใช้งาน Selectors ของ jQuery ในการอ้างถึง element ต่าง ๆ (text Selector()

โพสต์ที่ยังไม่ได้อ่าน โดย M008 »

text Selector(): เป็นการใช้ Selectors กับ :text Selector() คืออ้างถึง element ทั้งหมดที่มี input type="text"
Syntax

โค้ด: เลือกทั้งหมด

jQuery(':text')
ตัวอย่างการใช้งาน

โค้ด: เลือกทั้งหมด

<html>
<head>
<style>
	textarea { height:25px; }
</style>
<script type="text/javascript" src="jquery-1.6.4.js"></script>
<script type="text/javascript">

		$(document).ready(function(){

			var input = $("form input:text").css({background:"yellow", border:"3px red solid"});
			$("div").text("For this type jQuery found " + input.length + ".")
					.css("color", "red");
			$("form").submit(function () { return false; }); // so it won't submit

		});

</script>
</head>
<body>

  <form>
    <input type="button" value="Input Button"/>
    <input type="checkbox" />

    <input type="file" />
    <input type="hidden" />
    <input type="image" />

    <input type="password" />
    <input type="radio" />
    <input type="reset" />

    <input type="submit" />
    <input type="text" />
    <select><option>Option</option></select>

    <textarea></textarea>
    <button>Button</button>
  </form>
  <div>
  </div>
</body>
</html>
ผลลัพธ์
14.jpg
14.jpg (31.79 KiB) Viewed 1973 times
คำอธิบายใต้รูป
จากตัวอย่างเป็นการใช้ Selectors กับ :text Selector() ในการอ้างถึง element var input = $("form input:text") ที่มี input type="text" มีการกำหนด .css({background:"yellow", border:"3px red solid"}); จะมีผลแค่ <input type="text" />
  • Similar Topics
    ตอบกลับ
    แสดง
    โพสต์ล่าสุด

ผู้ใช้งานขณะนี้

สมาชิกกำลังดูบอร์ดนี้: Bing [Bot] และบุคลทั่วไป 71