2017-11-10 9 views
-1

특정 단어를 텍스트 영역의 다른 단어로 바꾸려면 자바 스크립트 기능을 작성하는 데 도움이 필요합니다.자바 스크립트 : 텍스트 영역의 특정 키워드 공백 교체

내가 입력 텍스트에 배치 된 단어 (들) 사이에 빈 공간을 찾아 텍스트 영역에서 대체 할

: 어떤 도움이 많이

밥을 이해할 수있을 것이다

<html> 
<head> 
<title>Replace Specific words in textarea</title> 
</head> 
<body> 
<Form name="frm" method="post" id="frm"> 
<TextArea name="txtArea1" cols="85" rows="10" ID="Textarea1"> 
While it was clear that forwarding the material was naughty (and the "culprits" had their wrists smacked), there. 
This is one of the#main#ways of using link events. If you have not seen rollover images before, they are images 
</TextArea><br> 
Input keywords: <Input type="text" name="findwords" value="the main ways" id="text1"> 
<Input type="submit" name="btnSubmit" value="Submit" id="submit"> 
</form> 
</body> 
</html> 

: 예를 들어

+0

원하는대로 정확하게 작성하십시오. 대체 후 결과는 무엇입니까? – iArcadia

+0

텍스트 영역에있는 입력 키워드의 공백을 "#"으로 대체하십시오. 예를 들어 다음과 같습니다 : 입력 텍스트 : "주요 방법"

+0

텍스트 영역 내에있는 키워드의 인스턴스를 고려하면 ... –

답변

0

실제로 이해할 수는 없지만 시도해보십시오.

// Execute instructions when the button with ID "submit" is clicked. 
document.getElementById('submit').addEventListener('click', function() 
{ 
    // Get user inputs. 
    var search = document.getElementById('text1').value; 
    // Replace spaces and tabs with a regular expression. 
    var alteredSearch = search.replace(/\s/g, '#'); 
    // Get the textarea content. 
    var look = document.getElementById('Textarea1').value; 

    // Finally, replace the textarea content. 
    document.getElementById('Textarea1').value = look.replace(new RegExp(search, 'g'), alteredSearch); 
}); 

양식이 있습니다. 현재 제출 버튼을 누르면 페이지가 다시로드되고 아무 것도 수행되지 않습니다. 자바 스크립트를 사용하려면 유형 입력을 button으로 설정하십시오.

+0

Ok. 입력 버튼을 "button"으로 설정했지만, JS 코드를