如有必要,可以在链接中添加http

use*_*459 2 html javascript jquery

以下是在jquery确认框中显示的字符串.

warningString = "<p style='margin-top: 12px;'>Please Verify the following URL is a valid Redirect URL.</p> <a href= " + redirURL + "' target='_blank'>" + redirURL + "</a><p style='margin-top: 8px;'> By clicking verify you are confirming this is a valid URL and will proceed with checkout. </p>";
Run Code Online (Sandbox Code Playgroud)

我希望链接添加http://如果变量redirURL缺少它.我对如何做到有点失落.

谢谢

Gab*_*abe 7

那怎么样:

if(redirURL.IndexOf('http') !== 0)
  redirURL = 'http://' + redirURL;
warningString = "<p style='margin-top: 12px;'>Please Verify the following URL is a valid Redirect URL.</p> <a href= " + redirURL + "' target='_blank'>" + redirURL + "</a><p style='margin-top: 8px;'> By clicking verify you are confirming this is a valid URL and will proceed with checkout. </p>";
Run Code Online (Sandbox Code Playgroud)

  • `<0`可能不是最好的解决方案(`www.httpd.com`).试试`!== 0`. (2认同)