我无法设法让 jQuery 添加 #quote 的内容(这是一个带有通过 foresmatic API 生成的字符串的段落)。完整的代码在这里:https://codepen.io/raffaele2692/pen/GvrvxM .... 你能帮助我吗? :)
<a type="button" class="twitter-share-button"
href="https://twitter.com/intent/tweet"
data-size="small"
data-text="">
Tweet</a>
<script>
var textQuote = document.getElementByID("#quote");
$("a").attr("data-text", textQuote);
</script>
最佳答案
您的 js 代码存在一些问题。您不需要在 getElementByID 调用的 id 中添加“#”,也可以使用 text 获取 HTML 元素的文本。方法。
<script>
var textQuote = $("#quote").text();
$("a").attr("data-text", textQuote);
</script>
关于javascript - 通过 jquery/javascript 将文本添加到 Twitter 分享 API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45542752/