Submitting form with js while ? is missing in the return result

I write a form submit thread with the attr method:

var href = a.attr('href');
      if(href =='') return;
      if(href.startsWith('http') || href.startsWith('//:')){
        a.attr('href',href.trim());
        if(href.indexOf(location.hostname) > -1){
          return;
        }
        if(href.indexOf('<?php echo $_SERVER['SERVER_NAME']; ?>') > -1){
          return;
        }

        a.attr('href','go.htm?uri='+href);
        a.attr('rel','nofollow');
      }

However, it returns the URL without ?, for example, I want to return https://example.abc.com/?ref=abc, the return result will be https://example.abc.com/ref=abc without “?” the question mark.

I’m struggling with solving this and I appreciate any helpful tips.