challenge: Converts the characters &, <, >, " (double quote), and ' (single quote) in a string to their corresponding HTML entities. If you get stuck, use Read-Search-Ask. Try exchanging programming ideas with others, but write your own code. For example:
Answer:
function convert(str) { var list = { "&":"&", "<":"<", ">":">", '"':"", "'":"'", }; for(var key in list){ str=str.replace(new RegExp(key,"g"),list[key]); } return str; } convert("Dolce & Gabbana"); Running results:
Online test: HTML symbol to entity algorithm challenge | w3cschool Summarize This is the end of this article about the challenge of converting HTML symbols to entities. For more relevant content about converting HTML symbols to entities, please search for previous articles on 123WORDPRESS.COM or continue to browse the related articles below. I hope you will support 123WORDPRESS.COM in the future! |
<<: How to create a MySQL master-slave database using Docker on MacOS
>>: Detailed example of locating and optimizing slow query sql in MySQL
Error scenario Use the mysql command in cmd to ad...
This article will discuss these 4 principles as t...
What is CN2 line? CN2 stands for China Telecom Ne...
1. Install tools and libraries # PCRE is a Perl l...
I encountered this problem before when developing...
Table of contents Preface Confusing undefined and...
Preface Bash has many important built-in commands...
Table of contents Preface Ajax serial and paralle...
The effect we need to achieve: What is needed The...
Knowledge point 1: Set the base URL of the web pa...
Introduction: The configuration of Docker running...
What is my.ini? my.ini is the configuration file ...
Overview of MySQL MySQL is a relational database ...
Simple example of HTML checkbox and radio style b...
This article example shares the specific code of ...