如何使用';window.location.href';在jQuery HTML中插入还是换行?

如何使用';window.location.href';在jQuery HTML中插入还是换行?,jquery,insert,replace,uri,word-wrap,Jquery,Insert,Replace,Uri,Word Wrap,我正在尝试将链接插入id为“popup”的空。该链接将在弹出框中打开当前页面(带有稍后定义的参数)。我正在尝试将制作超链接所需的HTML与JS变量“window.location.href”串在一起——如何将它们串在一起?i、 e.如何修复此问题以使其正常工作,或将其作为变量“window.location.href”重写为函数: $("#popup").html('<a href=' . window.location.href . '>open popup</a>')

我正在尝试将链接插入id为“popup”的空。该链接将在弹出框中打开当前页面(带有稍后定义的参数)。我正在尝试将制作超链接所需的HTML与JS变量“window.location.href”串在一起——如何将它们串在一起?i、 e.如何修复此问题以使其正常工作,或将其作为变量“window.location.href”重写为函数:

$("#popup").html('<a href=' . window.location.href . '>open popup</a>');
$(“#弹出”).html(“”);
像这样:

$("#popup").html($('<a />', { href: window.location.href, text: 'open popup' }));
$("#popup").html('<a href="' + window.location.href + '">open popup</a>');

您最初的方法有两个问题:

$("#popup").html('<a href=' . window.location.href . '>open popup</a>');
像这样:

$("#popup").html($('<a />', { href: window.location.href, text: 'open popup' }));
$("#popup").html('<a href="' + window.location.href + '">open popup</a>');

您最初的方法有两个问题:

$("#popup").html('<a href=' . window.location.href . '>open popup</a>');

顺便说一句:在javascript中,您将字符串与
+
组合,而不是
(PHP,对吗?):


顺便说一句:在javascript中,您将字符串与
+
组合,而不是
(PHP,对吗?):


这将更改链接,因此href是相同的

$("#popup").attr('href',window.location.href);
e、 g


这将更改链接,因此href是相同的

$("#popup").attr('href',window.location.href);
e、 g


#popup
似乎是一个容器,而不是锚定标记。
#popup
似乎是一个容器,而不是锚定标记。您需要对URL中的任何HTML特殊字符进行编码+1用于不带HTML字符串的版本!三,。您需要对URL中的任何HTML特殊字符进行编码+1用于不带HTML字符串的版本!很高兴你喜欢它,希望它能直接回答你的问题。不过,我建议您做更多的研究,因为您可能会发现弹出窗口的不同方法更易于重用。看看这个弹出式插件的源代码,你会得到一些启发。很高兴你喜欢它,希望它能直接回答你的问题。不过,我建议您做更多的研究,因为您可能会发现弹出窗口的不同方法更易于重用。看看这个弹出式插件的源代码,从中获得一些灵感。
<a id="popup" href="">popup</a>
<a id="popup" href="yourcurrenturl">popup</a>
 <a href="http://www.developertipoftheday.com" rel="popup" target="alexsite">open alex site in popup</a>
$("a[rel = 'popup']").click(function (event) {

    var popupWindow= window.open($(this).attr("href"), $(this).attr("target"), "status=true,toolbar=false,menubar=false,location=false,width=1018,height=792")

    if (popupWindow=== null) {

        alert("A messasge to inform the user, that the popup has been blocked");
    }

});