我正在尝试将JS链接到html,以便当用户单击推文图标时,它会自动填充Twitter中的推文框...我的代码只是打开盒子但没有填充它......有什么建议吗?
function makeId() {
var rNumber = Math.floor(Math.random() * quotes.length);
$("#quote > h1").html(quotes[rNumber]);
}
$("#press").on('click', function() {
$("#quote > h1").fadeOut('slow', function(){
makeId();
$(this).fadeIn('slow');
});
});
$("#icon > a").click(function(){
window.open("https://twitter.com/intent/tweet?text=" + makeId());
})
我的整个代码都在这里 - https://codepen.io/buzz_lightyear/pen/gXLLpo?editors=1010
我为您修复了它,而不是创建/选择新 ID,您需要将当前 ID 的值添加到 url。
$("#icon > a").click(function(){
window.open("https://twitter.com/intent/tweet?text=" + makeId());
})
应替换为
$("#icon > a").click(function(){
window.open("https://twitter.com/intent/tweet?text=" + $("#quote > h1").html());
})