2017-11-10 4 views
-1

特定の単語をテキストエリア内の他の単語に置き換えるjavascript関数を作成するのに役立つ必要があります。Javascript:テキストエリア内の特定のキーワードの空白スペースを置換する

私は、入力されたテキストの上に置いワード(複数可)の間の空白を見つけて、テキストエリアに置き換えたい

:すべてのヘルプははるかに

ボブに理解されるであろう

<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に設定すると、JavaScriptが機能します。

+0

Ok。私は入力ボタンを "ボタン"に設定しましたが、あなたのJSコードを

関連する問題