您的位置:首页 > Web前端 > JQuery

JQuery对元素的常用操作

2015-09-18 16:13 501 查看
jQuery对元素常用操作

1.redio  checkbox
$('input:radio[name=""][value=""]').prop('checked', true); //初始化
$('input:radio[name=""][value=""]').prop('checked', true);
2.select
$('#select option[value="0"]').attr("selected",true);  //初始化
3.事件
$('#select').trigger("change"); //触发change事件
4.选择
$('#select').nextAll('select'); //id为select的后续的所有select兄弟元素
$('#select').nextAll('select')[0];//id为select的后续的所有select兄弟元素的第一个
$('#select').nextAll();//id为select的后续的所有兄弟元素
$('#select').next();  //下一个兄弟元素
$('#select').next('select');//下一个select兄弟元素

$('#select').find('option[value=""]')  //

//ajax
$.ajax({
type:"POST",
async: false,
data:{'isLoad':'-1'},
url:"",
dataType:"json",
success:function(json){
$.each(json,function(index,comment){
//alert(comment['']);
//alert(comment.**);
});
}
});

动态加载JS文件的三种方法 http://www.jb51.net/article/42942.htm 
js 获取项目的根目录
var root = {
getRootPath:function () {
var curWwwPath = window.document.location.href;
var pathName = window.document.location.pathname;
var pos = curWwwPath.indexOf(pathName);
var localhostPath = curWwwPath.substring(0, pos);
var projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1);
return projectName;
}
}

var base = root.getRootPath();

加载页面并执行JS
$("#storeContainer").load("url",function(html){
$.getScript("*.js",function(){});
});
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: