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


d3.js namespace()用法及代碼示例

d3.namespace()函數用於返回一個對象,該對象包含空間和描述完整名稱空間URL和本地名稱的本地屬性。如果名稱中包含冒號,則冒號左側的字符串為名稱空間前綴。

用法:

d3.namespace(name);

參數:此函數僅包含上麵給出和下麵描述的一個參數。

  • name:這是一個包含必須在d3.namespaces中注冊的前綴的字符串。

返回值:此函數返回一個對象。

範例1:



HTML

<!DOCTYPE html> 
<html lang="en"> 
  
<head> 
    <meta charset="UTF-8" /> 
    <meta name="viewport" path1tent="width=device-width,  
        initial-scale=1.0" /> 
    <script src="https://d3js.org/d3.v4.min.js"> 
    </script> 
  
    <style> 
        h2 { 
            color:green; 
        } 
    </style> 
</head> 
  
<body> 
    <h2>Geeks for geeks</h2> 
    <script> 
        console.log(d3.namespace("svg:Geeksforgeeks")); 
        document.write("<h3>Space:",  
            d3.namespace("svg:Geeksforgeeks").space, "</h3>"); 
        document.write("<h3>Local:",  
            d3.namespace("svg:Geeksforgeeks").local + "</h3>"); 
    </script> 
</body> 
  
</html>

輸出:

範例2:

HTML

<!DOCTYPE html> 
<html lang="en"> 
  
<head> 
    <meta charset="UTF-8" /> 
    <meta name="viewport" path1tent="width=device-width,  
        initial-scale=1.0" /> 
  
    <script src="https://d3js.org/d3.v4.min.js"> 
    </script> 
</head> 
  
<body> 
    <script> 
        console.log(d3.namespace("xhtml:Geeksforgeeks")); 
        console.log(d3.namespace("xlink:Geeksforgeeks")); 
        console.log(d3.namespace("xml:Geeksforgeeks")); 
    </script> 
</body> 
  
</html>

輸出:




相關用法


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