Archive For The “javascript学习” Category
JS自身没有 trim这样的函数 来去除左右空格 ,必须通过自定义函数来实现这样的功能了。 代码如下: function trim(str){ return str.replace(/(^\s*)|(\s*$)/g, ""); }
javascript 实现TRIM功能 去掉字符串左右空格函数 <SCRIPT LANGUAGE="JavaScript"> // Trim() , Ltrim() , RTrim() String.prototype.Trim = function() { return this.replace(/(^\s*)|(\s*$)/g, ""); } String.prototype.LTrim = function() { return this.replace(/(^\s*)/g, ""); } String.prototype.RTrim = function() { return this.replace(/(\s*$)/g, ""); } </SCRIPT> str = str.replace(/[ ]/g,""); //替换所有空格 str.replace(/(^\s*)|(\s*$)/g, ""); //去掉左右空格 str.replace(/(\s*$)/g, ""); //去掉右空格 str.replace(/(^\s*)/g, ""); //去掉左空格
如果 smarty的标签跟js的语法冲突你会怎么办呢? 一般,冲突的地方注要有两个,一个是 smarty 的定界符 {} 与 js 语法的{}冲突 ,第二个是 jquery 的 $ 与smarty 变量的 $冲突 。 第一个问题 可以把 smarty 的定界符设成 $tpl->left_delimiter = ‘<{‘; $tpl->right_delimiter = ‘}>’; 第二个问题可以用 smarty 的 literal 处理,可以把 JS代码 包含在 {literal}{/literal} 之间就可以了。 <{literal}> $ ( function () { alert (’北京php培训’)} ); <{/literal}>
png透明 AlphaImageLoader filter:progid:DXImageTransform.Microsoft.AlphaImageLoader( enabled=bEnabled,sizingMethod=sSize,src=sURL) enabled:可选项。布尔值(Boolean)。设置或检索滤镜是否激活。true:默认值。滤镜激活。false:滤镜被禁止。 sizingMethod:可选项。字符串(String)。设置或检索滤镜作用的对象的图片在对象容器边界内的显示方式。crop:剪切图片以适应对象尺寸。image:默认值。增大或减小对象的尺寸边界以适应图片的尺寸。scale:缩放图片以适应对象的尺寸边界。 src:必选项。字符串(String)。使用绝对或相对 url 地址指定背景图像。假如忽略此参数,滤镜将不会作用。 firefox不能对innerText支持 firefox支持innerHTML但却不支持innerText,它支持textContent来实现innerText,不过默认把多余的空格也保留了。如果不用textContent,如果字符串里面不包含HTML代码也可以用innerHTML代替。 禁止选取网页内容 在IE中一般用js: obj.onselectstart=function(){return false;} 而firefox用CSS:-moz-user-select:none 滤镜的支持(例:透明滤镜) IE:filter:alpha(opacity=10); firefox:-moz-opacity:.10; 捕获事件 IE: obj.setCapture() 、obj.releaseCapture() Firefox: document.addEventListener(”mousemove”,mousemovefunction,true); document.removeEventListener(”mousemove”,mousemovefunction,true); 获取鼠标位置 IE:event.clientX、event.clientY firefox:需要事件函数传递事件对象 obj.onmousemove=function(ev){ X= ev.pageX;Y=ev.pageY; } DIV等元素的边界问题 比如:设置一个div的CSS::{width:100px;height:100px;border:#000000 1px solid;} IE中:div的宽度(包括边框宽度):100px,div的高度(包括边框宽度):100px; 而firefox:div的宽度(包括边框宽度):102px,div的高度(包括边框宽度):102px; 判断浏览器类型 var isIE=document.all ? true : false; 我写了一个变量,如果支持document.all语法那么isIE=true,否则isIE=false 在不同浏览器下的CSS处理 一般可以用!important来优先使用css语句(仅firefox支持) 比如:{border-width:0px!important;border-width:1px;} 在firefox下这个元素是没有边框的,在IE下边框宽度是1px document.formName.item(”itemName”) 问题 问题说明:IE下,可以使用 document.formName.item(”itemName”) [...]
<!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> <title>JS的动态时间效果 </title> <meta http-equiv=”Content-Type” content=”text/html; charset=gbk” /> <meta name=”generator” content=”editplus” /> <meta name=”author” content=”fanglor” /> <meta name=”keywords” content=”js时钟,js动态时间,js时钟效果” /> <meta name=”description” content=”一个用JS实现的时时变化的动态时钟效果” /> </head> <body> <span id=”time”></span> <script language=”javascript” type=”text/javascript”> window.onload=function (){ setInterval(“document.getElementById(‘time’).innerHTML=new Date().toLocaleString()+’ 星期’+’日一二三四五六’.charAt(new Date().getDay());”,1000); } </script> </body> </html>
content相当于你例子中的FCKeditor1。//获取格式化的编辑器内容 function getEditorContents(){ var oEditor = FCKeditorAPI.GetInstance(“content”); alert(oEditor.GetXHTML(true)); } //向编辑器插入指定代码 function insertHTMLToEditor(codeStr){ var oEditor = FCKeditorAPI.GetInstance(“content”); if (oEditor.EditMode==FCK_EDITMODE_WYSIWYG){ oEditor.InsertHtml(codeStr); }else{ return false; } } //统计编辑器中内容的字数 function getLength(){ var oEditor = FCKeditorAPI.GetInstance(“content”); var oDOM = oEditor.EditorDocument; var iLength ; if(document.all){ iLength = oDOM.body.innerText.length; }else{ var r = oDOM.createRange(); r.selectNodeContents(oDOM.body); iLength = r.toString().length; } alert(iLength); } //执行指定动作 function ExecuteCommand(commandName){ var oEditor = FCKeditorAPI.GetInstance(“content”) ; oEditor.Commands.GetCommand(commandName).Execute() ; } //设置编辑器中内容 function SetContents(codeStr){ var oEditor = FCKeditorAPI.GetInstance(“content”) ; oEditor.SetHTML(codeStr) ; }
