发布时间:2025-12-09 12:01:54 浏览次数:1
escapeXml()方法用于转义指定字符串中存在的XML标记语言的字符。
用法:
escapeXml(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>输出:
GeeksforGeeksGeeks<abc>for</abc>GeeksGeeksforGeeks
范例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.