Archive for 六月, 2009
-
六 19, 2009
No Commentsjquery 处理表单元素得到焦点与失去焦点
/*处理表单元素得到焦点与失去焦点*/ jQuery('.input_text').focus(function(){ var i = jQuery(this).attr('init_val'); var t = jQuery(this).attr('user_val'); if(i==undefined){ //记录初始值 jQuery(this).attr('init_val',jQuery(this).val()); jQuery(this).val(''); }else if(i==jQuery(this).val()){ jQuery(this).val(''); }else{ jQuery(this).val(t); } jQuery(this).css('color','#333'); }).blur(function(){ i = jQuery(this).attr('init_val'); if(jQuery(this).val()==''|| jQuery(this).val()==i){ jQuery(this).css('color','#bbb'); jQuery(this).val(jQuery(this).attr('init_val')); }else{ jQuery(this).attr('user_val',jQuery(this).val()); jQuery(this).css('color','#333'); }...
-
六 18, 2009
No Comments用于解决iframe自适应高度
function reinitIframe(){ var iframe = document.getElementById("frame_content"); try{ var bHeight = iframe.contentWindow.document.body.scrollHeight; var dHeight = iframe.contentWindow.document.documentElement.scrollHeight; var height = Math.max(bHeight, dHeight); iframe.height = height; }catch (ex){} } window.setInterval("reinitIframe()", 1000); 在新浪站上看到的不错,收藏下. 目前我们自己常用的 调用页面. 被调用页面 window.onload = function(){ var height = Math.max(document.body.scrollHeight, document.documentElement.scrollHeight); parent.call_frame(height)...
-
六 12, 2009
No Commentssmarty截取中文字符乱码问题解决方案(这个比较完整了)-转
改良的smartTruncate: 文件名:modifier.smartTruncate.php 以上代码完整实现了truncate的原有功能,而且可以同时兼容GB2312和UTF-8编码,在判断字符长度的时候,一个中文字符算1.0,一个英文字符算0.5,所以在截取子字符串的时候不会出现参差不齐的情况. 插件的使用方式没有特别之处,这里简单测试一下: {$content|smartTruncate:5:”..”}($content等于”A中B华C人D民E共F和G国H”) 显示:A中B华C.. (中文符号长度算1.0,英文符号长度算0.5,并且考虑省略符号的长度)...
-
六 10, 2009
No Comments今天写的一个练习的js类模式
suspendcode="" document.write(suspendcode); var hp = { lastScrollY : 0, byID : function(_id){ return document.getElementById(_id);}, init : function(id){ var st = document.documentElement.scrollTop || document.body.scrollTop; percent=.1*(st-this.lastScrollY); if(percent>0){ percent=Math.ceil(percent); }else{ percent=Math.floor(percent); } this.byID(id).style.top=parseInt(this.byID(id).style.top)+percent+"px"; this.lastScrollY=this.lastScrollY+percent; return id; }, generate : function(){ }, start : function(id){ window.setInterval("hp.init(’"+id+"’)",1); } };...