gpt4 book ai didi

jquery - 将查询字符串添加到 URL

转载 作者:行者123 更新时间:2023-12-01 03:22:40 25 4
gpt4 key购买 nike

var EventAddress=$(".EventAddress").text();
$(".EventDirectionLink a").attr("href", url + EventAddress);

这是我用来从表格单元格获取地址值并将其作为查询字符串传递到 map url 的 jquery,但它不起作用?我做错了什么??

<div class="driving-directions-link">
<a href="http://maps.google.com/maps?q=">Get Direction</a>
</div>

<table cellpadding="10" class ="EventDetail">
<tr>
<td class="TableFields">Who Should Enroll?:</td>
<td>Everyone 18 and older who would like to attend</td>
</tr>
<tr>
<td class="TableFields">Location:</td>
<td class="EventAddress">1300 Albany Street,Beech Grove ,IN</td>
</tr>
</table>

最佳答案

试试这个:

$('td.EventAddress').click(
function(){
$(".driving-directions-link a").attr("href", $(this).attr('href') + encodeURIComponent($(this).text));
});

JS Fiddle demo .

稍微简化一下上面的内容,以避免使用 .attr() 方法两次(不必要的第二次):

$('td.EventAddress').click(function(){
$(".driving-directions-link a").attr("href", function(i, h) {
return h + encodeURIComponent($(this).text());
});

JS Fiddle demo .

引用文献:

关于jquery - 将查询字符串添加到 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8555412/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com