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.
相关用法
- Lodash _.method()用法及代码示例
- Node.js Http2ServerRequest.method用法及代码示例
- Node.js http.IncomingMessage.method用法及代码示例
- Javascript dataView.getInt16()用法及代码示例
- Javascript RegExp toString()用法及代码示例
- Node.js URLSearchParams.has()用法及代码示例
- JavaScript Math cosh()用法及代码示例
- HTML DOM isEqualNode()用法及代码示例
- JavaScript Date toLocaleTimeString()用法及代码示例
- Node.js crypto.createHash()用法及代码示例
- Node.js writeStream.clearLine()用法及代码示例
- Node.js fs.link()用法及代码示例
- JavaScript Math random()用法及代码示例
- JavaScript Math round()用法及代码示例
- Javascript toString()用法及代码示例
- Javascript Number.isInteger( )用法及代码示例
- Javascript Number.isFinite()用法及代码示例
- Javascript toFixed()用法及代码示例
- Javascript toPrecision()用法及代码示例
- JavaScript Math abs()用法及代码示例
- JavaScript Math sqrt()用法及代码示例
- JavaScript Math floor()用法及代码示例
注:本文由纯净天空筛选整理自Kanchan_Ray大神的英文原创作品 Fabric.js escapeXml() Method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。