Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 添加绝对超链接URL_Javascript_Jquery_Html - Fatal编程技术网

Javascript 添加绝对超链接URL

Javascript 添加绝对超链接URL,javascript,jquery,html,Javascript,Jquery,Html,我有jquery代码的一部分 success: function(results) { if (results.d.Product.length > 1) { var html = '<h3>' + results.d.Product+ '<h3>' + '<div>' + results.d.ProductDescription + '</div>'

我有jquery代码的一部分

 success: function(results) {
        if (results.d.Product.length > 1) {
            var html = '<h3>' + results.d.Product+ '<h3>'
                    + '<div>' + results.d.ProductDescription + '</div>'
                    + '**<a href="#">' + results.d.Url + '</a>';**
            $(test).html(html);
        } 
成功:功能(结果){
如果(结果d.产品长度>1){
var html=''+results.d.Product+''
+''+results.d.ProductDescription+''结果
+ '**';**
$(test).html(html);
} 
我需要加一个绝对地址

我该怎么做呢

谢谢,
SA

您的代码不会转义这些值(除非在服务器上转义)

最好这样做:

$(test)
    .empty()
    .append($('<h3 />').text(results.d.Product))
    .append($('<div />').text(results.d.ProductDescription))
    .append(
        $('<a />')
            .attr('href', "http://yourdomain.tld/" + results.d.Url)
            .text(results.d.Url)
        );
$(测试)
.empty()
.append($('').text(results.d.Product))
.append($('').text(results.d.ProductDescription))
.附加(
$('')
.attr('href',”http://yourdomain.tld/“+results.d.Url)
.text(results.d.Url)
);

我假设您正试图这样做。请注意,如果服务器上的URL已经存在,您可能需要从域名字符串中删除
/

您正在制作锚定标记,这会阻止绝对URL的使用。请更具体一些。