【jquery】一天一条名言警句
先发表一篇文章用来存储所有名言警句(最好用<pre>...</pre>), 如:http://www.cnblogs.com/k-sharp/articles/2073017.html
再把下面的jquery代码粘贴到: 博客后台管理>页脚Html代码!
<script>
if($.browser.msie)
{
$("#blogTitle h2").html('IE is bad! Keep away from it. Download <a href="http://www.firefox.com/">firefox</a> now!').attr('title','firefox makes your life easy');
}
else
{
$.ajax({
url: 'http://www.cnblogs.com/k-sharp/articles/2073017.html',
dataType: 'html',
beforeSend: function() {
var msg = String.fromCharCode(9760,9760,9760,9760,9760,9760);
$("head title").text(msg);
$("#blogTitle h2 a").text(msg);
},
success: function(data) {
if(!data)
return;
var qs = $(data).find("#cnblogs_post_body pre").text().split(/\n+/);
var q = qs[Math.floor(Math.random() * qs.length)];
$("head title").text(q);
$("#blogTitle h2 a").text(q)
},
error: function() {
var msg = String.fromCharCode(9775,9775,9775,9775,9775,9775);
$("head title").text(msg);
$("#blogTitle h2 a").text(msg);
}
});
$('#blogTitle h2 a').live('click', function() {
$(this).replaceWith($("<input>").val($(this).text()));
$('#blogTitle h2 input').css("width", "90%").select();
});
$('#blogTitle h2 input').live('focusout', function() {
$(this).replaceWith($("<a>").attr('title', 'click to select this quote').text($(this).val()));
});
}
</script>
效果如我的主页:
1. 每次打开页面都会随机取一条名言警句, 显示在标题下面;
2. 鼠标点击后,会变成一个文本框,并且会选中所有文字,方便复制/粘贴;
3. 鼠标点击文本框外,恢复到以前的状态。
注:
1.根据自己的情况修改黄色标记的两行!(用firefox的firebug查看)
2.不支持IE
3.CSS要自己调整一下
推荐.NET配套的通用数据层ORM框架:CYQ.Data 通用数据层框架