简体   繁体   English

JavaScript字符串串联错误

[英]Javascript string concatenation error

<a href="#">{{ meeting.date }}</a>


$('.meet a').click(function() {
    var txt = $(this).text();
    var url = "http://localhost:8000/meeting_display/" + txt;
    $("a").attr("href", url);
});

In the above function, I am trying to go to a url on click on the anchor element. 在上面的函数中,我尝试单击锚元素上的URL。 But everytime, the value of url is " http://localhost:8000/meeting_display/%20 *value of txt * 但是每次url的值都是“ http:// localhost:8000 / meeting_display /%20 * txt的值*

Thus I am not able to create a hyperlink to the intended page. 因此,我无法创建指向预期页面的超链接。 Please help me. 请帮我。

As @alex said, use trim to remove blank space : 正如@alex所说,使用trim删除空格:

<a href="#">{{ meeting.date }}</a>


$('.meet a').click(function() {
    var txt = $(this).text();
    txtTrim = $.trim(txt);
    var url = "http://localhost:8000/meeting_display/" + txtTrim;
    $("a").attr("href", url);
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM