Fabric.js escapeXml() 方法

Fabric.js escapeXml() 方法

escapeXml() 方法用于转义指定字符串中 XML 标记语言中的字符。

语法:

escapeXml(string)

参数:

该方法接受一个参数,如上所述,并在下面进行描述:

  • string: 该参数保存要转义的字符串。

返回值:

该方法返回指定字符串的转义版本。

示例1:

<!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:

<!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.

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程