คุณสมบัติ Location pathname ส่งกลับ/ตั้งค่าสตริงที่สอดคล้องกับชื่อพาธ URL
ไวยากรณ์
ต่อไปนี้เป็นไวยากรณ์ -
- คืนค่าของ ชื่อพาธ ทรัพย์สิน
location.pathname
- ค่าของชุดคุณสมบัติ href
location.pathname = pathOfHost
ตัวอย่าง
ให้เราดูตัวอย่างสำหรับ ชื่อเส้นทางของตำแหน่ง ทรัพย์สิน −
<!DOCTYPE html>
<html>
<head>
<title>Location pathname</title>
<style>
form {
width:70%;
margin: 0 auto;
text-align: center;
}
* {
padding: 2px;
margin:5px;
}
input[type="button"] {
border-radius: 10px;
}
</style>
</head>
<body>
<form>
<fieldset>
<legend>Location-pathname</legend>
<label for="urlSelect">Current URL:</label>
<input type="url" size="30" id="urlSelect" value="https://www.example.com:2544/aboutUs/CTO.htm">
<input type="button" onclick="getpathname()" value="Get pathname">
<div id="divDisplay"></div>
</fieldset>
</form>
<script>
var divDisplay = document.getElementById("divDisplay");
var urlSelect = document.getElementById("urlSelect");
function getpathname(){
divDisplay.textContent = 'URL pathname: '+location.pathname;
}
</script>
</body>
</html> ผลลัพธ์
สิ่งนี้จะสร้างผลลัพธ์ต่อไปนี้ -
ก่อนคลิก 'รับชื่อพาธ' ปุ่ม −

หลังจากคลิก 'รับชื่อพาธ' ปุ่ม −
