此文旨在记录本人在学习过程中的经典例子
本部分提供完整的 JavaScript 参考手册:
- JavaScript 本地对象和内置对象
- Browser 对象(BOM)
- HTML DOM 对象
HTML DOM 对象参考手册
本参考手册描述每个对象的属性和方法,并提供实例。
相关页面
如需更多有关 JavaScript 对象的知识,请阅读 JavaScript 高级教程中的相关内容:
如需更多有关 DOM 的知识,请访问 W3School 提供的 XML DOM 教程:
如需更多有关 jQuery 的知识,请访问 W3School 提供的 jQuery 教程:
注释:jQuery 是一个 JavaScript 库,它极大地简化了 JavaScript 编程。
javascript
在线资料: http://www.w3school.com.cn/js/index.asp
正则表达式实例(判断IP是否正确)
<script type="text/javascript">
var str="192.168.1.2"
document.write(str.match(/(\d{1,3}[.]){3}\d{1,3}/g)) //其中match参数中必须以 '/'开头和结尾,最后的g表示全局匹配
</script>
jQuery
在线资料: http://www.w3school.com.cn/jquery/
例1.
function switchMandatory(inputEltId, mode){ if("ON" == mode){ if(jQuery("#"+inputEltId+"> span").size() == 0) /*用来判断一个id是否存在*/ jQuery("#"+inputEltId).append("<span class='field-mandatory'>*</span>"); /*在某个对象后面加入html代码*/ }else if("OFF"){ jQuery("#"+inputEltId+"> span").remove(); /*删除整个对象*/ } }
例2. 关于 validate的使用
jQuery("#phoneHome").validate({
expression: "", /*表达式*/
message: "" /*false时打印的消息*/
,check: true /*载入是就检查*/
});
ajax
例1.
jQuery.ajax({
url: _controlPath + "storeAndReload", /*指定url*/
cache: false,
data:{"store_id":id, "rememberMe":rememberMeChx, "isTunnel": jQuery("isTunnel").val()}, /*指定传递的参数*/
success: function(){/*成功调用指定url后执行的代码*/
if(rememberMeChx == 'on'){
setCookie("STORE", id, days, "/", "", ""); /*把指定数据放进cookie中*/
}else{
setCookie("STORE", "", 0, "/", "", "");
}
$HidePopup();
var $fieldIdToSet = jQuery("#favouriteStoreId");
if($fieldIdToSet.size() != 0) {
$fieldIdToSet.val(id);
jQuery("#favouriteStoreMessageStoreName").html(storeName);
jQuery("#favouriteStoreMessageNoStore").hide();
jQuery("#favouriteStoreMessageStoreChose").show();
} else {
window.location.reload();
}
}
});
转自:http://www.w3school.com.cn/js/js_reference.asp