แอตทริบิวต์HTML src
ความหมายและการใช้งาน
แอตทริบิวต์src
ระบุตำแหน่ง (URL) ของทรัพยากรภายนอก
นำไปใช้กับ
สามารถใช้ แอตทริบิวต์src
กับองค์ประกอบต่อไปนี้:
องค์ประกอบ | คุณลักษณะ |
---|---|
<เสียง> | src |
<embed> | src |
<iframe> | src |
<img> | src |
<input> | src |
<script> | src |
<translation> | src |
<track> | src |
<video> | src |
ตัวอย่าง
ตัวอย่างเสียง
เครื่องเล่นเสียง:
<audio src="horse.ogg" controls>
Your browser does not support the audio element.
</audio>
ฝังตัวอย่าง
แอนิเมชั่นแฟลชแบบฝัง:
<embed src="helloworld.swf">
ตัวอย่างไอเฟรม
<iframe> ในการใช้งานที่ง่ายที่สุด:
<iframe src="/default.asp"></iframe>
Img ตัวอย่าง
ภาพถูกทำเครื่องหมายขึ้นดังนี้:
<img src="smiley.gif" alt="Smiley face">
ตัวอย่างอินพุต
แบบฟอร์ม HTML ที่มีรูปภาพแทนปุ่มส่ง:
<form action="/action_page.php">
First name: <input type="text" name="fname"><br>
<input type="image" src="submit.gif" alt="Submit">
</form>
ตัวอย่างสคริปต์
ชี้ไปที่ไฟล์ JavaScript ภายนอก:
<script src="myscripts.js"></script>
ตัวอย่างที่มา
เครื่องเล่นเสียงที่มีไฟล์ต้นฉบับสองไฟล์ เบราว์เซอร์ควรเลือกไฟล์ที่รองรับ (ถ้ามี) สำหรับ:
<audio controls>
<source src="horse.ogg" type="audio/ogg">
<source src="horse.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
ติดตามตัวอย่าง
วิดีโอที่มีแทร็กคำบรรยายสองแทร็ก:
<video width="320" height="240" controls>
<source src="forrest_gump.mp4" type="video/mp4">
<source src="forrest_gump.ogg" type="video/ogg">
<track src="subtitles_en.vtt" kind="subtitles" srclang="en" label="English">
<track src="subtitles_no.vtt" kind="subtitles" srclang="no" label="Norwegian">
</video>
ตัวอย่างวิดีโอ
เล่นวิดีโอ:
<video src="movie.ogg" controls>
Your browser does not support the video tag.
</video>
รองรับเบราว์เซอร์
แอตทริบิวต์src
มีการสนับสนุนเบราว์เซอร์ต่อไปนี้สำหรับแต่ละองค์ประกอบ:
Element | |||||
---|---|---|---|---|---|
audio | 4.0 | 9.0 | 3.5 | 4.0 | 10.5 |
embed | Yes | Yes | Yes | Yes | Yes |
iframe | Yes | Yes | Yes | Yes | Yes |
img | Yes | Yes | Yes | Yes | Yes |
input | 1.0 | 2.0 | 1.0 | 1.0 | 1.0 |
script | Yes | Yes | Yes | Yes | Yes |
source | 4.0 | 9.0 | 3.5 | 4.0 | 10.5 |
track | 18.0 | 10.0 | 31.0 | 6.0 | 15.0 |
video | 4.0 | 9.0 | 3.5 | 4.0 | 10.5 |