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

jquery 相关操作笔记

2013-01-10 13:44 393 查看
设置当前值选中:

1:遍历

str = xxx;
$("#xxx option").each(function(){if($(this).text() == str){
$(this).attr("selected",true);
}
});

同理根据val

str = xxx;
$("#xxx option").each(function(){if($(this).val() == str){
$(this).attr("selected",true);
}
});



2:利用选择器:

$("#xxx option[value='xxx']").find("option[value='xxx']").attr("selected",true);//option[value='xxx'] 不支持text


3:获取值:

$('#xxx option:selected').html();或者val


3:value绑定的是json 判断 json相等代码:

/*
*json比较相等
*/
function compareObject(jsonObj1, jsonObj2) {
if (typeof jsonObj1 != typeof jsonObj2) return false;
if (typeof jsonObj1 == 'object') {
for (var o in jsonObj1) {
if (typeof jsonObj2[o] == 'undefined') return false;
if (!compareObject(jsonObj1[o], jsonObj2[o])) return false;
}
return true;
} else {
return jsonObj1 === jsonObj2;
}
}


选择器:

子页面(iframe查找父页面id)

$(window.parent.document.getElementById("iframeShowBadPoint"))


父页面调用子页面方法(iframe)

ifmMap.window.fnSeMapType($(this).val());


ifmMap是子页面的iframe的name , fnSeMapType("xx")是子页面的方法。

jquery 解析xml IE失败解决。

success: function (result) {
var res;
if($.browser.msie){
res = new ActiveXObject("Microsoft.XMLDOM");
res.async = false;
res.loadXML(result.d);
}else{
res = result.d;
}
var xmlConten=$(res).find("marker");
if(xmlConten.length>0){xmlConten.each(function(){
})
}else{
//no data;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐