에 저장이이 코드가 있습니다자바 스크립트를 분할 문자로 단어와 배열
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Bad Grammar Generator</title>
</head>
<body>
<input type="text" id="userIn">
<input type="button" name="name" id="btn" value="Bad Grammar-ify" onclick="badgrammar()">
<span id="output"></span>
<script type="text/javascript">
var userIn = document.getElementById("userIn").value;
function badgrammar() {
var userIn = document.getElementById("userIn").value;
var output = document.getElementById("output");
var split = new Array();
split = userIn.split(" ");
output.innerText = split;
}
</script>
</body>
</html>
그것은 작동을하지만, 한 단어로 사용자 입력을 분할합니다. 편지로 사용자 입력을 어떻게 분할 할 수 있습니까?
예 :
입력 : Hi there
출력 : H,i,t,h,e,r,e
'userIn.split ("");'(공백이 없으면) 개별 문자로 분할되지만 공백을 제외 시키겠다는 소리가 나나요? – smarx