无法在 JavaScript 字符串中工作
好的,我的网站有一个基于 javascript 的 Twitter 插件。
的 innerHTML 打印出“推文内容”
我使用 Jquery ajax 获取 JSON,然后使用我网站上标签
...一切正常,但我想制作所有主题标签和 @ 链接。我这样设置的方式似乎是有效的,但由于某种原因,CSS 样式表会对链接进行样式设置,但是浏览器不会将链接视为链接。
var dynamicString = data[0].text;
var dispString = "";
while(dynamicString.indexOf("#") != -1)
{
var indexOfHash = 0;
var indexOfSpace =0;
var indexOfHash = dynamicString.indexOf("#");
dispString += dynamicString.slice(0, indexOfHash);
dynamicString = dynamicString.slice(indexOfHash, dynamicString.length);
indexOfSpace = dynamicString.indexOf(" ");
dispString += "<a class='twitterlink' href='http://twitter.com/#!/search/%23";
dispString += dynamicString.slice(1, indexOfSpace);
dispString += "'>" + dynamicString.slice(0, indexOfSpace) + "</a>";
dynamicString = dynamicString.slice(indexOfSpace, dynamicString.length);
}
dispString += dynamicString;
var twitterPTag = document.getElementById('lasttweet');
twitterPTag.innerHTML = "<span id='tweettitle'>Latest Tweet:</span><br />" + dispString;
我的网站是 justinmburrous.com,查看该脚本正在运行的任何页面。
Okay I have a javascript based twitter plugin for my my website.
I use Jquery ajax to get the JSON, and I then print out the "tweeted content" with the innerHTML of a
tag on my site...
That all works fine, however I wanted to make all of the hashtags and @ links. They way I have this set up is seems to be working, but for some reason the css style sheets will style the link, however the borwser does not treat the links as links.
var dynamicString = data[0].text;
var dispString = "";
while(dynamicString.indexOf("#") != -1)
{
var indexOfHash = 0;
var indexOfSpace =0;
var indexOfHash = dynamicString.indexOf("#");
dispString += dynamicString.slice(0, indexOfHash);
dynamicString = dynamicString.slice(indexOfHash, dynamicString.length);
indexOfSpace = dynamicString.indexOf(" ");
dispString += "<a class='twitterlink' href='http://twitter.com/#!/search/%23";
dispString += dynamicString.slice(1, indexOfSpace);
dispString += "'>" + dynamicString.slice(0, indexOfSpace) + "</a>";
dynamicString = dynamicString.slice(indexOfSpace, dynamicString.length);
}
dispString += dynamicString;
var twitterPTag = document.getElementById('lasttweet');
twitterPTag.innerHTML = "<span id='tweettitle'>Latest Tweet:</span><br />" + dispString;
My website is justinmburrous.com, check out any page for this script working, live.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
更改
它太宽且 z-index 高于链接
Change
it is too wide and the z-index higher than the link