2016-03-23 87 views

回答

1
var x="pokemon,rykrkr"; 
y=x.split(","); 

document.getElementById('ok').innerHTML=y[0]; 
1

這是pokemon,rykrkr的第一個字符,您正在顯示,但您需要拆分的單詞。

var x = "pokemon,rykrkr", 
 
    words = x.split(","); 
 

 
document.getElementById('ok').innerHTML = words[0];
<div id="ok"></div>

3

.split不會改變原來的字符串,所以你必須做這樣的:

var x = "pokemon,rykrkr"; 
 
var splited = x.split(","); 
 

 
document.getElementById('ok').innerHTML = splited[0];
<div id="ok"></div>