如何从数据属性中删除单引号

时间:2016-06-23 08:13:47

标签: javascript jquery

我需要从标记中删除单引号,因为它与页面上的某些javascript功能冲突。对我来说,最好的方法是什么?

<span class="field-content" data-live-anchor="jes's-mon">Group A</span>

1 个答案:

答案 0 :(得分:0)

这有助于您:

<html>
<head>
</head>
    <body>
        <span class="field-content" data-live-anchor="jes's-mon">Group A</span>
       <script>
          var ele = document.getElementsByClassName("field-content")[0];
           str = ele.getAttribute("data-live-anchor");
           var newStr = str.replace(/\'/gmi,'');
           alert(newStr);
        </script>
    </body>
</html>