手机
当前位置:查字典教程网 >编程开发 >Javascript教程 >用jquery仿做发微博功能示例
用jquery仿做发微博功能示例
摘要:源代码:复制代码代码如下:发布框$(function(){$("#content").focus(function(){if($(this)...

源代码:

复制代码 代码如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>发布框</title>

<script src="../scripts/jquery-1.3.1.js" type="text/javascript"></script>

<>

<script type="text/javascript">

$(function(){

$("#content").focus(function(){

if ($(this).val()==this.defaultValue) {

$(this).val("");

//alert($(this).length-1);

}

}).blur(function(){

if ($(this).val()=='') {

$(this).val(this.defaultValue);

}

})

$("#content").keyup(function(){

//alert($(this).val().length);

var words_num = 140 - $(this).val().length;

if (words_num < 0) {

//被误导了 这样是不会有 return 值的

//$("font").text(function(words_num){

// return "<font color='red'>"+words_num+"</font>";

//});

$("font").css('color','red').text(words_num);

}else{

$("font").text(words_num);

//alert(words_num);

}

})

});

$(function(){

$("#send").click(function(){

$.post("post3.php", {

// username : $("#username").val() ,

content : $("#content").val()

}, function (data, textStatus){

// var username = data.username;

var content = data.content;

// var txtHtml = "<div><h6>"+username+":</h6><p>"+content+"</p></div>";

var txtHtml = "<div><h3>"+content+"</h3></div>";

$("#resText").html(txtHtml); // 把返回的数据添加到页面上

},"json");

})

});

</script>

</head>

<body>

<fieldset>

<legend>发布框</legend>

<form action="#" id="form1"><>

您还可以输入<span id="num"><font color="green">140</font></span>个字

<textarea cols="96" rows="8" id="content">随便写点东西吧.</textarea>

<input type="button" id="send" value="发布"/>

</form>

</fieldset>

<div>你发送的信息是:</div>

<div id="resText">

</div>

</body>

</html>

效果图:

1

遇到的问题:

主要就是jquery库的问题:使用jquery-1.3.1.js这个文件,能实现功能,但是使用jquery-1.7.1.min.js这个文件,就没有效果!害我花了很多时间去源代码找问题!!

【用jquery仿做发微博功能示例】相关文章:

js实现简单div拖拽功能实例

繁简字转换功能

JQuery中DOM事件冒泡实例分析

JQuery中DOM加载与事件执行实例分析

JQuery球队选择实例

jquery滚动特效集锦

jQuery结合ajax实现动态加载文本内容

用JavaScript实现页面重定向功能的教程

jquery实现图片左右切换的方法

jQuery插件bgStretcher.js实现全屏背景特效

精品推荐
分类导航