HTML DOM Input URL form 属性

htmlweb developmentfront end technology更新于 2025/8/29 10:52:17

HTML DOM Input URL 表单属性返回输入 URL 的封装表单的引用。

语法

以下是语法 −

返回表单对象的引用

inputURLObject.form

示例

让我们看一个 Input URL form 属性的示例 −

<!DOCTYPE html>
<html>
<head>
<title>Input URL form</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 id="Larry Page">
<fieldset>
<legend>URL-form</legend>
<label for="URLSelect">URL :
<input type="URL" id="URLSelect" size="25">
</label>
<input type="button" onclick="getform()" value="Get Co-founder">
<div id="divDisplay"></div>
</fieldset>
</form>
<script>
   var divDisplay = document.getElementById("divDisplay");
   var inputURL = document.getElementById("URLSelect");
   function getform() {
      if(inputURL.value !== '')
         divDisplay.textContent = 'Co-founder: '+inputURL.form.id;
      else
         divDisplay.textContent = 'Please enter valid URL';
   }
</script>
</body>
</html>

输出

这将产生以下输出 −

点击"获取联合创始人"按钮前 −

勾选"获取联合创始人"按钮后 −


相关文章


有用资源