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


Fabric.js escapeXml()用法及代碼示例

escapeXml()方法用於轉義指定字符串中存在的XML標記語言的字符。

用法:

escapeXml(string)

參數:此方法接受如上所述和以下描述的參數:

  • string:此參數保存要轉義的字符串。

返回值:此方法返回指定字符串的轉義版本。

範例1:



Javascript

<!DOCTYPE html> 
  
<html> 
  
<head> 
   <script src= 
"https://cdnjs.cloudflare.com/ajax/libs/fabric.js/3.6.2/fabric.min.js" > 
   </script> 
  
   <script type="text/javascript" src= 
"https://cdnjs.cloudflare.com/ajax/libs/fabric.js/3.6.2/fabric.min.js.map"> 
   </script> 
  
   <script type="text/javascript" src= 
"https://cdnjs.cloudflare.com/ajax/libs/fabric.js/3.6.2/fabric.js"> 
   </script> 
</head> 
  
<body> 
   <script type="text/javascript"> 
        // Printing a string with the help 
        // of escapeXml() function  
        // without the characters of XML 
        console.log(fabric.util.string.escapeXml("GeeksforGeeks")); 
          
        // Printing a string with the help 
        // of escapeXml() function  
        // with the characters of XML 
        console.log(fabric.util.string.escapeXml("Geeks<abc>for</abc>Geeks")); 
          
        // Printing a string without the help 
        // of escapeXml() function  
        // with the characters of XML 
        console.log("Geeks<abc>for</abc>Geeks"); 
   </script> 
  
</body> 
  
</html>

輸出:

GeeksforGeeks
Geeks<abc>for</abc>Geeks
GeeksforGeeks

範例2:

Javascript

<!DOCTYPE html> 
  
<html> 
  
<head> 
   <script src= 
"https://cdnjs.cloudflare.com/ajax/libs/fabric.js/3.6.2/fabric.min.js" > 
   </script> 
  
   <script type="text/javascript" src= 
"https://cdnjs.cloudflare.com/ajax/libs/fabric.js/3.6.2/fabric.min.js.map"> 
   </script> 
  
   <script type="text/javascript" src= 
"https://cdnjs.cloudflare.com/ajax/libs/fabric.js/3.6.2/fabric.js"> 
   </script> 
</head> 
  
<body> 
   <script type="text/javascript"> 
        console.log("Using escapeXml() Function:"); 
        var value="GFG <a> is a CS </a> portal."; 
        console.log(fabric.util.string.escapeXml(value)); 
          
        console.log("Without using escapeXml() Function:"); 
        var value="GFG <a> is a CS </a> portal."; 
        console.log(value); 
   </script> 
  
</body> 
  
</html>

輸出:

Using escapeXml() Function:
GFG <a> is a CS </a> portal.
Without using escapeXml() Function:
GFG is a CS portal.

相關用法


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