随笔分类 -  jQuery

摘要:利用jquery等库的选择器可以不再依赖于特定的ID或类名,而且可以减少很多代码,以下实例说明:效果:点击article标签里面的nav标签里面的a链接,弹出框“点击了连接”js写法:function linksnum(){var article=document.getElementsByTagName("article");for(var a=0;a<article.length;a++){var nav=article[a].getElementsByTagName("nav");for(var n=0;n<nav.length;n++ 阅读全文
posted @ 2013-04-07 20:24 tinyphp 阅读(1257) 评论(0) 推荐(0)
摘要:一般我们会var text=document.getElementById("text"); 拿到text元素再定义属性,但是如果要拿的id很多,就会发现一个页面里面,document.getElementById就占一大块代码,其实只要写一次就够了:function $(e){ return document.getElementById(e);}有了这个函数,想设置text为显示,那么就写:$("text").display="block";是不是简单很多呢? 阅读全文
posted @ 2013-03-29 17:34 tinyphp 阅读(285) 评论(0) 推荐(0)
摘要:点击后:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE> New Document </TITLE> <style> body{font-size:14px;} input{border:none;font-size:14px;} .show{} .hide{border:1px solid #ccc;background-color:#eee;width:150px;height:2 阅读全文
posted @ 2013-03-29 17:08 tinyphp 阅读(719) 评论(0) 推荐(0)
摘要:预览图:index.php点击这里run.php";echo "获取的id:".$id;?>jquery.js自己上网下载一份即可!jQ的相对于js的简单很多相关文章:js+Ajax+PHP 简单实例jQuery ajax - post() 方法 阅读全文
posted @ 2013-03-27 23:49 tinyphp 阅读(1805) 评论(0) 推荐(0)
摘要:index.phpotxfor.phpa.jsvar xmlHttp; //定义XMLHttpReqest对象function S_xmlhttprequest(){ if(window.ActiveXObject){ xmlHttp=new ActiveXObject('Microsoft.XMLHTTP'); }else if(window.XMLHttpRequest){ //如果浏览器支持XMLHttpRequest对象,创建ActiveXObject对象 xmlHttp=new XMLHttpRequest(); } } function fu... 阅读全文
posted @ 2013-03-27 22:09 tinyphp 阅读(721) 评论(0) 推荐(0)
摘要:为了更好的兼容,不是所有属性都能用setAttribute解决的,例如以下的(为什么加载了样式和层,部分效果失效?)设置样式:x.className="name';(为什么函数没有触发?)设置按钮的事件:x.onclick=func;(为什么文本框还是可以修改?)设置readonly只读:x.readOnly=true; 阅读全文
posted @ 2013-03-08 17:47 tinyphp 阅读(140) 评论(0) 推荐(0)
摘要:<iframe id="topNav" src="xx.php"></iframe><script>var topWin = window.top.document.getElementById("topNav").contentWindow;alert(topWin);</script> 阅读全文
posted @ 2013-03-02 11:07 tinyphp 阅读(2159) 评论(0) 推荐(0)
摘要:JS调用form.submit() 出现对象不支持此属性或方法的原因:因为网页代码里有一个submit按钮名字叫submit <input type="submit" name="submit" value="提交"/>只要把这个名称改一下,改成:<input type="submit" name="submit2" value="提交"/> 问题解决。 阅读全文
posted @ 2013-03-02 09:38 tinyphp 阅读(5476) 评论(0) 推荐(0)
摘要:如:echo $product;结果为:{"brand":"佳能","category":"单反相机"}json_decode解析:$web=json_decode($product);这时候你print_r($web);可以看到:$web是一个对象stdClass Object([brand] => 佳能[category] => 单反相机}想拿里面的值echo $web->brand; //得到佳能 阅读全文
posted @ 2013-01-22 15:07 tinyphp 阅读(26498) 评论(0) 推荐(0)
摘要:在ie中,有些标签的innerHTML属性是只读的,如下:COL, COLGROUP, FRAMESET,html, STYLE, TABLE, TBODY, TFOOT, THEAD, TITLE, TR 阅读全文
posted @ 2013-01-18 12:06 tinyphp 阅读(413) 评论(0) 推荐(0)
摘要:今天遇到一个问题,就是动态添加option到slect里面在ie6不成功:<script>var shosetype=document.createElement("select"); shosetype.setAttribute("id","sc");document.body.appendChild(shosetype);var option="<option value=\"1\">添加成功</option>";shosetype.innerHTML=o 阅读全文
posted @ 2013-01-17 18:27 tinyphp 阅读(48138) 评论(0) 推荐(1)
摘要:想循环的时候累加字符串,然后这样写,是没有效果的<script>function dd(){for(var i=0; i<2;i++){var op+="sdfsd";}alert(op);}dd();</script>因为声明的时候是不能累加的,var x+=...这样的写法本身就是错误,这样就可以了<script>function dd(){var op="";for(var i=0; i<2;i++){op+="sdfsd";}alert(op);}dd();</script 阅读全文
posted @ 2013-01-17 16:46 tinyphp 阅读(23776) 评论(2) 推荐(2)
摘要:<script>function fun1(){var str = '[{"uname":"王宝强","day":"2012/06/17"},{"uname":"李连杰","day":"2012/08/12"}]'; var jsonList=eval("("+str+")"); //转换为json对象for(var i=0;i<jsonList.length;i 阅读全文
posted @ 2013-01-16 18:02 tinyphp 阅读(12301) 评论(0) 推荐(0)
摘要:var btn1Obj = document.getElementById("btn1");举例:btn1Obj.onclick = method1;btn1Obj.onclick = method2;btn1Obj.onclick = method3;如果这样写,最终将会只有medhot3被执行使用attachEvent添加事件,如: attachEvent('onload'......|attachEvent("onclick".....写成这样:btn1Obj.attachEvent("onclick",meth 阅读全文
posted @ 2013-01-12 15:03 tinyphp 阅读(780) 评论(0) 推荐(0)
摘要:http://localhost/getDomainData.html<!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" > <meta http-equiv="Content-Type" content=&qu 阅读全文
posted @ 2013-01-12 11:31 tinyphp 阅读(619) 评论(0) 推荐(0)
摘要:date.html:放在127.0.0.3域名下<!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" xml:lang="en"><head> <meta http-equiv="Content 阅读全文
posted @ 2013-01-11 18:19 tinyphp 阅读(1907) 评论(0) 推荐(0)
摘要:<?php$arr = array ('a'=>1,'b'=>2,'c'=>3,'d'=>4,'e'=>5);echo json_encode($arr);?> 以上例程会输出:{"a":1,"b":2,"c":3,"d":4,"e":5}得到某值例子:<?php$arr = array ('a'=>1,'b'=>2,' 阅读全文
posted @ 2013-01-10 17:41 tinyphp 阅读(3737) 评论(0) 推荐(0)
摘要:什么是 JSON ?JSON 指的是 JavaScript 对象表示法(JavaScript Object Notation)JSON 可通过 JavaScript 进行解析JSON 数据可使用 AJAX 进行传输能够使用内建的 JavaScript eval() 方法进行解析实例:<div id="name"></div><div id="age"></div><script>var jsonobject={"name":"bill","age 阅读全文
posted @ 2013-01-10 15:38 tinyphp 阅读(659) 评论(0) 推荐(0)
摘要:什么是跨域?JavaScript出于安全方面的考虑,不允许跨域调用其他页面的对象。但在安全限制的同时也给注入iframe或是ajax应用上带来了不少麻烦。这里把涉及到跨域的一些问题简单地整理一下:首先什么是跨域,简单地理解就是因为JavaScript同源策略的限制,a.com 域名下的js无法操作b.com或是c.a.com域名下的对象。相关文章:JavaScript跨域总结与解决办法如何解决js跨域问题网页里做异步的跨域请求js跨域传输数据实例(单向)js跨域数据传输实例(双向) 阅读全文
posted @ 2013-01-10 15:06 tinyphp 阅读(183) 评论(0) 推荐(0)
摘要:很多网站都具备了利用书签按钮“一键提交”的功能,其实一点儿也不复杂,只要掌握了在收藏夹中使用js,就可以为书签工具增色不少。(不过ie浏览器不支持,一般用浏览器插件代替)下面例子的所有代码都需要填写在书签的地址栏(Location)中。例子1:先来一个最简单的例子,只包含一个js函数:javascript:alert(document.lastModified);点击这个书签项目,将会弹出一个提示框,显示当前网页的生成时间例子2:修改Html:<form method="post" name="Form1"><input type=&q 阅读全文
posted @ 2013-01-04 11:34 tinyphp 阅读(1773) 评论(0) 推荐(0)