Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have two html text input, out of that what ever user type in first text box that need to reflect on second text box while reflecting it should replace all spaces to semicolon. I did to some extant and it replacing for first space not for all, I think I need to use .each function of Jquery, I have used .each function but I didn't get the result see this

HTML :

Title : <input type="text" id="title"><br/>
Keyword : <input type="text" id="keyword">

Jquery:

$('#title').keyup(function() {
    var replaceSpace = $(this).val(); 

        var result = replaceSpace.replace(" ", ";");

        $("#keyword").val(result);

});

Thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
152 views
Welcome To Ask or Share your Answers For Others

1 Answer

var result = replaceSpace.replace(/ /g, ";");

Here, / /g is a regex (regular expression). The flag g means global. It causes all matches to be replaced.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...