当前位置: 首页 > 图文教程 > 网络编程 > Javascript > 常用JS代码实例小结

Javascript
form中限制文本字节数js代码
use jscript with List Proxy Server Information
use jscript List Installed Software
List Installed Software Features
List Information About the Binary Files Used by an Application
List the Codec Files on a Computer
List the UTC Time on a Computer
List Installed Hot Fixes
excel操作之Add Data to a Spreadsheet Cell
Add Formatted Data to a Spreadsheet
Apply an AutoFormat to an Excel Spreadsheet
JavaScript语法着色引擎(demo及打包文件下载)
类之Prototype.js学习
一款JavaScript压缩工具:X2JSCompactor
iis6+javascript Add an Extension File
jscript之Open an Excel Spreadsheet
jscript之Read an Excel Spreadsheet
jscript之List Excel Color Values
去除图像或链接黑眼圈的两种方法总结
Add a Formatted Table to a Word Document

Javascript 中的 常用JS代码实例小结


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-10-12   浏览: 452 ::
收藏到网摘: n/a

跟网上的一些常用的不太一样,个人都有个人常用的代码,大家看到好东西,不一定什么都会,起码要知道有这么个东西。方便以后用也方便找。 1. 键盘方向键监听事件和禁止复制操作
点击运行可以看到效果:
[Ctrl+A 全选 提示:你可先修改部分代码,再按运行]
重新定义HTML元素的大小 实例代码:
点击运行可以看到效果:
[Ctrl+A 全选 提示:你可先修改部分代码,再按运行]

取得Iframe中的文档的内容
复制代码 代码如下:

<script>
//因WINDOWS的安全机制,只能读取相同域名下的iframe内容
function GetIframeInnerHtml(objIFrame)
{
var iFrameHTML = "";
if (objIFrame.contentDocument)
{
// For NS6
iFrameHTML = objIFrame.contentDocument.innerHTML;
}
else if (objIFrame.contentWindow)
{
// For IE5.5 and IE6
iFrameHTML = objIFrame.contentWindow.document.body.innerHTML;
}
else if (objIFrame.document)
{
// For IE5
iFrameHTML = objIFrame.document.body.innerHTML;
}
return iFrameHTML;
}
</script>
<iframe src="test.htm" id="frmIn" name="frmIn"></iframe>
<input type="button" value="click" onclick="alert(GetIframeInnerHtml(document.all.frmIn))">

JQUERY 判断复选框选中 -- 单选同理
复制代码 代码如下:

$("input[type=checkbox]:checked").each(function() { alert($(this).attr("id"))});

我总结的常用jquery的一些例子:
1.隐藏所有包含连接的段落
$("p[a]").hide()
2.显示页面中的第一个段落
$("p:eq(0)").show()
3.隐藏当前显示的所有div
$("div:visible").hide()
4.获取ul下所有li项
$("ul / li") [注意这里面没有空格,是因为QQ的那该死的表情会自己出现] 或者$("ul>li")
5.获取所有样式为foo的包含连接的段落
$("p.foo[a]")
6.获取无序列表项中包含"BBB"文本的所有连接
$("li[a:contains('BBB')]")
7.获取那么属性为bar的input标签
$("input[@name=bar]")
8.获取所有选中的单选按钮
$("input[@type=radio][@checked]")
不确认关闭[不支持FF]
复制代码 代码如下:

<a href="#" onclick="window.opener=null;window.open('','_self');window.close();">不确认关闭</a>

jquery 将页面中所有的 text 文本框设为null
$(":text").val();
iframe跨域问题的解决思路
代理不垮域
跨子域
location跳转
var associative_array = new Array();
associative_array["one"] = "1";
associative_array["two"] = "2";
associative_array["three"] = "3";
if(associative_array.length > 0) {
// to do 这里的associative_array.length永远是0 是因为JS数组下标只能是数字
}
判断数组
function isArray(o) { return Object.prototype.toString.call(o) === '[object Array]';}