Check pressed space then add diez tag using jquery with multi language

前端 未结 7 1598
感动是毒
感动是毒 2021-01-17 08:06

I am trying to add Diez tag # after the pressed space using jquery when user type. I have created this DEMO from codepen.io.

In this d

7条回答
  •  春和景丽
    2021-01-17 08:50

    There is a simple Javascript function to do the functionality;

    function addDiszTag(str){
            //  var str = "Hi bro how are you?"
            str = str.split(' ');
    
            //Output will be turned to be ["Hi", "bro", "how", "are", "you?"]
            var transformedArr = [];
            str.forEach(function(ele){transformedArr.push("#"+ele) })
    
            // ["#Hi", "#bro", "#how", "#are", "#you?"]
    
            return transformedArr.join(' '); 
    
           //It will return "#Hi #bro #how #are #you?"
    
        }
    

    Please add validation for checking duplicate :-) Hope it helped

提交回复
热议问题