Alt attribute encoding with JavaScript

后端 未结 4 1600
深忆病人
深忆病人 2020-12-03 22:07

Html entities must be encoded in alt attribute of an image in HTML page. So

\"A
         


        
4条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-03 22:46

    Here's an alternative if you can't save your file using a Unicode format:

    function decodeHTML(str) {
        return str.replace(/&#(\d+);?/g, function() {
            return String.fromCharCode(arguments[1])
        });
    }
    

    However, this requires you to use the numeric representation. In this case .

提交回复
热议问题