[英]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
encode
为encodeURI
视为错误,则应使用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.