论坛首页 Web前端技术论坛

常用JS代码实例

浏览 42215 次
精华帖 (2) :: 良好帖 (1) :: 新手帖 (0) :: 隐藏帖 (18)
作者 正文
   发表时间:2009-01-15   最后修改:2009-04-07

1. 键盘方向键监听事件和禁止复制操作

<head>
<script language=javascript>
document.onkeydown=nextpage
var prevpage="http://www.xiaoshuo.com/jsp/readchapter.jsp?id=0011020986&chapter=18912&pageid=1"
var nextpage="http://www.xiaoshuo.com/jsp/readchapter.jsp?id=0011020986&chapter=18913&pageid=3"
var indexpage="/readindex/index_0011020986.html"
function nextpage(event) {
	event = event ? event : (window.event ? window.event : null); 
	if (event.keyCode==13) location=indexpage

	if (event.keyCode==37) location=prevpage

	if (event.keyCode==39) location=nextpage
}
</script>
<SCRIPT language=javascript>
function nocopy() 
{
alert("不允许复制");
event.returnValue=false;
}
</SCRIPT>
</head>


<body leftmargin="0"  oncopy=nocopy()>
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
//-->
</script>
<h1>禁止复制</h1>
</body>

 

 

jquery表操作实例,本来想加在留言中,但是javaeye的管理员很莫名其妙的老是隐藏我的帖子,帖子发了不到一分钟就被评委隐藏贴,我真佩服啊,暗箱操作换说是被大家评为隐藏贴,呵呵呵,我哪里发了垃圾贴了,我上午把prototype的lightboxhuanchengjquery的facybox所以发个帖子,谁知就直接评委隐藏贴了,难不成发那种感情贴就可以不隐藏,发技术贴就被隐藏!!!!

 

写道
//泰国气候中的表的渲染
BEUI.E.thailand_QH = function(){

//tbody中第一列居左 , 第3,5,7列字体加粗
$('table#thailand-qh tbody tr').each(function(){
$('td:even',this).css('font-weight','bold');
$('td:eq(0)',this).css({'text-align':'left','font-weight':'normal'});
});



$('table#thailand-qh tbody tr:odd').addClass('thailand-qh-tbody-tr-odd');
$('table#thailand-qh tbody tr:even').addClass('thailand-qh-tbody-tr-even');
};

 

 

  • 大小: 14.5 KB
   发表时间:2009-01-20  
重新定义HTML元素的大小 实例代码:


<script type="text/javascript" language="javascript">
function resize(obj) {
obj.style.width="500px";
}
</script>
</head>
<body>
<img src="http://www.iteye.com/upload/logo/user/35330/4e311ac1-0916-340c-83bf-e343e6f44427.jpg" onload="resize(this)" />
</body>

0 请登录后投票
   发表时间:2009-01-22  
取得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))">


0 请登录后投票
   发表时间:2009-02-02  
JQUERY 判断复选框选中 -- 单选同理
$("input[type=checkbox]:checked").each(function() { alert($(this).attr("id"))});
0 请登录后投票
   发表时间:2009-02-18  
我总结的常用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]")
0 请登录后投票
   发表时间:2009-02-26  
不确认关闭[不支持FF]

<a href="#" onclick="window.opener=null;window.open('','_self');window.close();">不确认关闭</a>
0 请登录后投票
   发表时间:2009-03-13  
jquery 将页面中所有的 text 文本框设为null
$(":text").val();

0 请登录后投票
   发表时间:2009-03-14  
iframe跨域问题的解决思路

代理不垮域
跨子域
location跳转
0 请登录后投票
   发表时间:2009-03-15  
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数组下标只能是数字
}
0 请登录后投票
   发表时间:2009-03-15  
function isArray(o) {  return Object.prototype.toString.call(o) === '[object Array]';}
0 请登录后投票
论坛首页 Web前端技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics