How do I concatenate a string with a variable?

前端 未结 5 1372
醉话见心
醉话见心 2020-11-22 16:26

So I am trying to make a string out of a string and a passed variable(which is a number). How do I do that?

I have something like this:

function AddB         


        
5条回答
  •  情深已故
    2020-11-22 17:11

    This can happen because java script allows white spaces sometimes if a string is concatenated with a number. try removing the spaces and create a string and then pass it into getElementById.

    example:

    var str = 'horseThumb_'+id;
    
    str = str.replace(/^\s+|\s+$/g,"");
    
    function AddBorder(id){
    
        document.getElementById(str).className='hand positionLeft'
    
    }
    

提交回复
热议问题