當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


HTML DOM isDefaultNamespace()用法及代碼示例

HTML DOM isDefaultNamespace() 方法返回一個布爾值(真/假),如果指定的命名空間是默認的與否。

Note − 元素節點繼承其父節點的命名空間,因此,XHTML 文檔中的所有元素都具有 namespaceURI "http://www.w3.org/1999/xhtml"。

用法

以下是語法 -

調用 isDefaultNamespace()

document.documentElement.isDefaultNamespace("nameSpaceURI")

示例

讓我們看一個例子isDefaultNamespace()方法 -

<!DOCTYPE html>
<html>
<head>
<title>isDefaultNamespace()</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>isDefaultNamespace( )</legend>
<label for="textSelect">URI:
<input type="url" size="25" id="textSelect" placeholder="http://www.abc.com">
</label><br>
<input type="button" onclick="confirmNameSpace()" value="Check">
<div id="divDisplay"></div>
</fieldset>
</form>
<script>
   var divDisplay = document.getElementById("divDisplay");
   var inputText = document.getElementById("textSelect");
   divDisplay.textContent = 'NOTE:Check if specified URI is DefaultNamespace';
   function confirmNameSpace() {
      if(document.documentElement.isDefaultNamespace(textSelect.value))
         divDisplay.textContent = 'Above given namespace is default';
      else
         divDisplay.textContent = 'Above given namespace is not default';
   }
</script>
</body>
</html>

輸出

這將產生以下輸出 -

點擊前‘Check’按鈕 -

點擊後‘Check’輸入無效的按鈕 -

點擊後‘Check’具有有效輸入的按鈕 -

相關用法


注:本文由純淨天空篩選整理自AmitDiwan大神的英文原創作品 HTML DOM isDefaultNamespace() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。