不知道里面有什么js_images[getImg]
,很难说出了什么问题。
要记住的一件事是,您应该始终在创建 URL 之前对组件进行编码。例如:
var x = encodeURIComponent(js_images[getImg].title)
$('#em_button').html('<a href="mailto:?subject=A Photo: '+ x +'&body...')
此外,如果您正在创建类似链接的内容,您可能希望通过如下方式编写它以使事情更清晰:
var url = 'mailto:subject=A Photo: ' + encodeURIComponent(js_images[getImg].title) +
'&body=I thought you would like this photo: ' + encodeURIComponent(thisPage) +
'&id=' + encodeURIComponent(getGall) +
'&img=' + encodeURIComponent(js_images[getImg].filename);
var src = encodeURIComponent(homeUrl) + '/' +
encodeURIComponent(tUrl) + '/img/email.png'
var $a = $('<a/>', {
href: url
});
var $img = $('<img/>', {
src: src,
title: 'Email this photo'
});
$a.append($img);
$('#em_button').html($a);
$('#em_button').html('<a href="mailto:?subject=A Photo: ' + js_images[getImg].title + '&body=I thought you would like this photo: ' + thisPage + '?id=' + getGall + '&img=' + js_images[getImg].filename + '"><img src="' + homeUrl + '/' + tUrl + '/img/email.png" title="Email this photo" /></a>');