与php的urlencode、urldecode相同功能的javascript版函数
decodeURIComponent(); //為urldecode的javascript版函數 encodeURIComponent(); //為urlencode的javascript版函數
2. 獲取網址#後面的內容可使用document.location.hash
例如:http://www.tmper.com/dreams/idea/edit/6?k=1232#top
var hash = document.location.hash; //可以获取地址中#top(锚点)
3. 显示javascript中json数据(即把javascript中的json数据转换成字符串再显示出來)
先到<font color=”blue”>http://json.org/</font> 下载json.js文件,然後使用stringify函数,见下例:
var myJSONObject = {"bindings": [
{"ircEvent": "PRIVMSG", "method": "newURI", "regex": "^http://.*"},
{"ircEvent": "PRIVMSG", "method": "deleteURI", "regex": "^delete.*"},
{"ircEvent": "PRIVMSG", "method": "randomURI", "regex": "^random.*"}
]
};
var myJSONText = JSON.stringify(myJSONObject ); //使用该函数可以直接显示JSON数据 相当于PHP的var_export([json], true)的使用
alert(myJSONText);
即可以使用alert把myJSONObject的內容全部显示出來,而不是只是显示一個[Object Element],详情見http://www.json.org/js.html
4. 利用Google Map Api,根據地址获取相对的国家和地理座标(经度、纬度)
显示源代码
5. 查看变量类型: typeof(var)
返回:
1)number;
2)string;
3)boolean;
4)object
5)function;
6)undefined.
6. 判断字符串中是否存在某一字符串: string.indexOf(string)..
如果不存在, 将返回-1. 存在刚返回所在位置坐标.
7. window.onload = function(){ }
网页加载完成后才执行的函数.
8. jQuery(Object).find(“option:selected”).text();
使用jQuery获取select中的某一已选中的option的相关内容.
除非注明,干草博客文章均为原创,转载请以链接形式标明本文地址
