javascript - 如有必要,将 http 添加到链接

标签 javascript jquery html

以下是显示在 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/

相关文章:

javascript - 我无法让 jQuery 或 jQuery UI 工作

javascript - 如何在每次刷新/加载页面时播放 "loop once"动画 GIF 背景?

javascript - 将变量从指令传递到 Controller

javascript - 当查询字符串不够长时,如何从 jQuery 调用(网络本地)第 3 方 Web 服务?

javascript - 为什么javascript中的匿名函数有名字?

javascript - 如何从 google map api 更改 map 位置?

html - 使用 Bootstrap 3 和 AngularJS 在输入字段后添加星号

javascript - Mozilla 插件开发 : Accessing LAST USED or LAST CHANGED fields in password manger

javascript - 使用 capybara ,我无法从 href 读取自定义数据属性

javascript - 按包含字符串的数据属性多重过滤表行