我想在JavaScript中拆分此字符串。
我试试看:
<!DOCTYPE html>
<html>
<body>
<p id="demo">Click the button to display the array values after the split.</p>
<button onclick="myFunction()">Try it</button>
<script>
function myFunction()
{
var str = "<new_a><new_b><sb_c>";
var res = str.split("<");
document.getElementById("demo").innerHTML=res;
}
</script>
</body>
</html>
结果: new_a&GT; ,new_b&gt; ,sb_c&gt;
我想要我的结果:new_a,new_b,sb_c
我该怎么办?
答案 0 :(得分:0)
function myFunction()
{
var str = "<new_a><new_b><sb_c>";
str = str.replace("<","");
str = str.replace(">"," ");
var res = str.split(" ");
document.getElementById("demo").innerHTML=res;
}
试试这段代码。