易截截图软件、单文件、免安装、纯绿色、仅160KB

Javascript 中对HTML编码和解码的方法

String.prototype.HTMLEncode = function() {
var temp = document.createElement ("div");
(temp.textContent != null) ? (temp.textContent = this) : (temp.innerText = this);
var output = temp.innerHTML;
temp = null;
return output;
}
String.prototype.HTMLDecode = function() {
var temp = document.createElement("div");
temp.innerHTML = this;
var output = temp.innerText || temp.textContent;
temp = null;
return output;
}
上面代码转自:http://www.jb51.net/article/18396.htm
本人对javascript的核心技术不是太熟悉,再加上现在又在用不熟悉的EXT来编写前台页面代码,所以只得用最笨的方法,不扩展String自己写处理函数:
htmlDecode:function(str){
  var temp = document.createElement ("div");
  temp.innerHTML = str;
    var output = temp.innerText || temp.textContent;
    temp=null;
  return output;
 }
htmlEncode:function(str){
  var temp = document.createElement ("div");
  (temp.textContent != null) ? (temp.textContent = str) : (temp.innerText = str); 
  var output = temp.innerHTML;
  temp = null;
  return output; 
 }
其中用到的textContent和innerText 属性取到的内容是一样的
原因是firefox不支持innerText属性,但其提供的textContent属性和innerText具有一样的作用。所以上面的代码可以兼容IE和firefox


相关文档:

JavaScript:prototype属性使用方法

一、基本使用方法
      prototype属性可算是JavaScript与其他面向对象语言的一大不同之处。
简而言之,prototype就是“一个给类的对象添加方法的方法”,使用prototype属性,可以给类动态地添加方法,以便在JavaScript中实现“继承”的效果。
    & ......

10个基于JavaScript的WYSIWYG(所见即所得)编辑器


在线编辑内容的时候,那些基于 JavaScript 的编辑器帮了我们大忙,这些所见即所得(WYSIWYG)编辑器,给我们提供了类似
Office 的操作体验。如今,任何网站内容管理系统(CMS)和博客系统都需要一个这样的编辑器。本文精选了10个基于 JavaScript 
的编辑器,它们有的是基于 jQuery 框架,有点则不是。
Mar ......

JavaScript使用技巧精萃

(一).确认删除用法:
  1. BtnDel.Attributes.Add("onclick","return confirm('"+"确认删除?"+"')");
  2. linktempDelete.Attributes["onclick"]="javascript:return  confirm('"+"确认删除?"+"');";
  3. privat ......

用JavaScript去除字符串的首尾空格。

String.prototype.Trim=function(){
returnthis.replace(/(^\s*)|(\s*$)/g,"");
}
String.prototype.LTrim=function(){
returnthis.replace(/(^\s*)/g,"");
}
String.prototype.RTrim=function(){
returnthis.replace(/(\s*$)/g,"");
} ......

用JavaScript检查文件是否存在

function checkImgAddr(url){
var xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
xmlhttp.open("post",url,false);
xmlhttp.send();
if(xmlhttp.readyState==4){
if(xmlhttp.status==404){
return "File Not Exist.";
}else if(xmlhttp.status == 200){
re ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号