当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。