以下是显示在 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>";
如果缺少变量 redirURL,我希望链接添加 http://。我对如何去做有点迷茫。
谢谢
最佳答案
那么怎么样:
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>";
关于javascript - 如有必要,将 http 添加到链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16989249/