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>

輸出

將會產生以下輸出 −

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

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

更新於: 30-Jul-2019

67 次瀏覽

開啟你的 職業 生涯

完成課程並獲得認證

開始行動
廣告