简体   繁体   English

javascript中的自动推文填充(引号)无法正常工作

[英]automatic tweet fill (quote) in javascript not working properly

i'm trying to link js to html so that when user clicks tweet icon it automatically fills up the tweet box in twitter...my code is only opening the box but not filling it...any suggestions? 我正在尝试将js链接到html,以便当用户单击tweet图标时,它会自动填满Twitter中的tweet框...我的代码只是打开该框而不填充它...任何建议?

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());
})

my whole code is here - https://codepen.io/buzz_lightyear/pen/gXLLpo?editors=1010 我的整个代码在这里-https://codepen.io/buzz_lightyear/pen/gXLLpo?editors=1010

I fixed it for you, instead of creating / selecting a new ID you needed to add the value of the current ID to the url. 我为您修复了该问题,而不是创建/选择一个新ID,而是需要在URL中添加当前ID的值。

$("#icon > a").click(function(){
  window.open("https://twitter.com/intent/tweet?text=" +  makeId());
})

should be replaced with 应该替换为

$("#icon > a").click(function(){
  window.open("https://twitter.com/intent/tweet?text=" + $("#quote > h1").html());
})

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

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