简体   繁体   English

如何将javascript生成的文本包含到html链接中?

[英]How to include javascript generated text into html link?

I have a javascript that displays a generated text into a div: document.getElementById('phrase').innerHTML = phrase; 我有一个JavaScript,可以将生成的文本显示到div中:document.getElementById('phrase')。innerHTML =短语; PHRASE_TEXT_GETS_SHOWN_HERE PHRASE_TEXT_GETS_SHOWN_HERE

Basically I'm trying to set up a link that will take the text and post it to twitter with a link: Clicky for tweety 基本上,我正在尝试建立一个链接,该链接将接受文本并将其通过以下链接发布到Twitter: Clicky for tweety

How can I include the generated text in the link? 如何在链接中包含生成的文本?

Do you mean like: 您的意思是:

function setPhrase(phrase) {
  var url = 'http://twitter.com/home?status=' + encode(phrase);
  $('#phrase').html('<a href="' + url + '">' + phrase + '</a>');
}

...? ...?

Un-jQuerying it should be straightforward enough, if that's how you roll. 如果这是滚动的方式,则取消jQuery应当足够简单。

This is un-jQueried: 这是不可查询的:

function setPhrase(phrase) {
  var url = 'http://twitter.com/home?status=' + encodeURI(phrase);
  document.getElementById('phrase').innerHTML = '<a href="' + url + '">' + phrase + '</a>';
}

If you didn't see my failbraining encode for encodeURI as an error you should use Firebug. 如果您没有将我的failbraining encodeencodeURI视为错误,则应使用Firebug。 It may also fail if you have more than one element with the id phrase or if you have no elements with the id phrase . 如果你有一个id多于一个元素,它也可能会失败, phrase或者如果你有与id的元素phrase

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

相关问题 如何将Javascript生成的文本包含到HTML div中并定义字体,大小等? - How to include Javascript-generated text into HTML div and define font, size etc? 将在javascript文件中生成的一行文本转换为HTML中的可点击链接 - Convert a line of text generated in a javascript file into a clickable link in HTML 如何获取由 javascript 生成的 html 输入的文本? - how to get the text of an html input generated by javascript? 如何将 div 链接到 JavaScript 生成的 HTML 中的一个容器? - How to link divs to one container within JavaScript generated HTML? 如何找到为 Javascript 生成的元素提供文本的链接? - How to find a link that provides a text for an element generated by Javascript? 替换javascript include中的html文本 - Replace html text in javascript include 如何在悬停覆盖图像中包含文本-仅HTML,CSS,JavaScript - How to include text with hover overlay image - HTML, CSS, JavaScript only JavaScript变量作为HTML链接文本 - JavaScript variable as HTML link text 如何在HTML页面中包含webpack生成的文件? - How to include webpack generated file in an HTML Page? 如何在Javascript生成的HTML表单中包含Django 1.2的CSRF令牌? - How do I include Django 1.2's CSRF token in a Javascript-generated HTML form?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM