HTML DOM Input URL name 属性
htmlweb developmentfront end technology更新于 2025/9/18 18:52:17
HTML DOM Input URL name 属性返回一个字符串,该字符串是输入 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>
输出
这将产生以下输出 −
点击"谁是所有者?"按钮之前 −

点击"谁是所有者?"按钮之后 −

相关文章
有用资源
html 参考教程 - 该教程包含有关 html 的更多信息:https://www.cainiaomax.com/html/

