HTML DOM Input URL name 屬性
HTML DOM Input URL name 屬性返回一個字串,即 Input URL 的 name 屬性值。使用者也可以將其設定成一個新的字串。
語法
以下是語法 −
- 返回字串值
inputURLObject.name
- 將 name 屬性設定成一個字串值
inputURLObject.name = ‘String’
示例
我們來看看 Input URL name 屬性的一個例子 −
<!DOCTYPE html>
<html>
<head>
<title>Input URL name</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>URL-name</legend>
<label for="URLSelect">Employee URL:
<input type="url" id="URLSelect" value="https://www.example.com" name="Jack">
</label>
<input type="button" onclick="getName()" value="Who is the Owner? ">
<div id="divDisplay"></div>
</fieldset>
</form>
<script>
var divDisplay = document.getElementById("divDisplay");
var inputURL = document.getElementById("URLSelect");
function getName() {
if(inputURL.value === 'https://www.example.com')
divDisplay.textContent = 'Above URL belongs to '+inputURL.name;
else
divDisplay.textContent = 'Above URL belongs to no one!';
}
</script>
</body>
</html>輸出
將會產生以下輸出 −
單擊 “所有者是誰?” 按鈕之前 −

單擊 “所有者是誰?” 按鈕之後 −

廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP