我有下面的Facebook片段,我使用它来允许我的站点用户将信息作为一个经典的asp页面的一部分发布到他们的Facebook墙上。它工作得非常完美。但是,我希望传入一个变量,以便在脚本中使用,这样post就包含了动态内容,但是我不知道如何。
在下面的示例中,我对document.getElementById('vCarPrice')的使用不起作用。
有人知道我做错了什么吗?
<div id="fb-root">
</div>
<script>
window.fbAsyncInit = function() {
FB.init({appId: '<insert app id here>', status: true, cookie: true,
xfbml: true});
};
(function() {
var e = document.createElement('script'); e.async = true;
e.src = document.location.protocol +
'//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
}());
</script>
<script type="text/javascript">
$(document).ready(function(){
$('#share_button').click(function(e){
e.preventDefault();
FB.ui(
{
method: 'feed',
name: 'Car Price News',
link: ' http://www.car.com/',
picture: 'http://www.car.com/logo.jpg',
caption: 'The Price of a saloon is now £' + **document.getElementById('vCarPrice')** + '. Buy Now!',
description: 'The place to be for all the latest car prices.',
message: ''
});
});
});
</script>
发布于 2014-05-21 22:15:46
与文档的其余部分相比,这些代码在哪里?document.getElementById()将返回一个HTML .根据要提取的信息类型而定,您可以执行类似document.getElementById('id').innerHTML或.value之类的操作,或者做一些实际获取所需文本的操作,而不是整个对象。
https://stackoverflow.com/questions/23794492
复制相似问题