线2:
#msdhoni
我want-什么,当用户输入一些东西在文本框(以行1)应该成为div的标题(在第2行)点击botton(在第1行)。其实想要用代码中的文本输入替换#msdhoni。
jQuery代码我米使用:(请建议在这段代码的变化,使这成为可能)
String.prototype.linkify=function(){
return this.replace(/[A-Za-z]+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&;\?\/.=]+/g,function(m){
return m.link(m);
});
};
String.prototype.linkuser=function(){
return this.replace(/[@]+[A-Za-z0-9-_]+/g,function(u){
return u.link("http://twitter.com/"+u.replace("@",""));
});
};
String.prototype.linktag=function(){
return this.replace(/[]+[A-Za-z0-9-_]+/,function(t){
return t;
});
};
var showTweetLinks='none';
function fetch_tweets(elem){
elem = $(elem);
keyword = escape(elem.attr('title'));
num=elem.attr('class').split(' ').slice(-1);
var url = "http://search.twitter.com/search.json?q=" +keyword+ "&rpp=" + num + "&callback=?";
$.getJSON(url,function(json){
$(json.results).each(function(){
var tTime=new Date(Date.parse(this.created_at));
var cTime=new Date();
var sinceMin=Math.round((cTime-tTime)/60000);
if(sinceMin==0){
var sinceSec=Math.round((cTime-tTime)/1000);
if(sinceSec<10)
var since='less than 10 seconds ago';
else if(sinceSec<20)
var since='less than 20 seconds ago';
else
var since='half a minute ago';
}
else if(sinceMin==1){
var sinceSec=Math.round((cTime-tTime)/1000);
if(sinceSec==30)
var since='half a minute ago';
else if(sinceSec<60)
var since='less than a minute ago';
else
var since='1 minute ago';
}
else if(sinceMin<45)
var since=sinceMin+' minutes ago';
else if(sinceMin>44&&sinceMin<60)
var since='about 1 hour ago';
else if(sinceMin<1440){
var sinceHr=Math.round(sinceMin/60);
if(sinceHr==1)
var since='about 1 hour ago';
else
var since='about '+sinceHr+' hours ago';
}
else if(sinceMin>1439&&sinceMin<2880)
var since='1 day ago';
else{
var sinceDay=Math.round(sinceMin/1440);
var since=sinceDay+' days ago';
}
var tweetBy='@'+this.from_user+' '+since+'';
if(showTweetLinks.indexOf('reply')!=-1)
tweetBy=tweetBy+' · RT';
var tweet='
'+this.text.linkify().linkuser().linktag().replace(/'+tweetBy+'
elem.append(tweet);
});
});
return(false);
}
$(function(){
showTweetLinks=showTweetLinks.toLowerCase();
if(showTweetLinks.indexOf('all')!=-1)
showTweetLinks='reply,view,rt';
$('.twitStream').each(function(){
fetch_tweets(this);
});
});
2012-02-23
Prashant