option隐藏,创建,对父页面的元素的操作
来源:互联网 发布:linux vsftpd chcon 编辑:程序博客网 时间:2024/06/05 17:30
因IE不支持option隐藏:觉得这个例子很好,就把它给复制下来了
<!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"> <head> <title>Untitled Page</title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script> <script type="text/javascript" language="javascript"> $(function(){ //Bind the change event $("#dropLang").unbind("change", eDropLangChange).bind("change", eDropLangChange); $("#dropFrame").unbind("change", eDropFrameChange).bind("change", eDropFrameChange);}); //The change event of language dropdown-list var eDropLangChange = function(){ //The selected value of the language dropdown-list. var selectedValue = $(this).val(); //show all options. $("#dropFrame").children("span").each(function(){ $(this).children().clone().replaceAll($(this)); //use the content of the <span> replace the <span> }); //Filter the data through selected value of language dropdown-list except <Please Select>. //If the option is <Please Select>, it only needs to show all and hide nothing. if(parseInt(selectedValue) != 0){ //hide the option whose parentid is not equal with selected value of language dropdown-list. //The <Please Select> option should not be hidden. $("#dropFrame").children("option[parentid!='" + selectedValue + "'][value!='0']").each(function(){ $(this).wrap("<span style='display:none'></span>"); //add a <span> around the <option> and hide the <span>. }); } }; //The change event of frame dropdown-list. var eDropFrameChange = function(){ //Find the selected option of frame dropdown-list. set the value of language dropdown-list by selected parentid. $("#dropLang").val($(this).children("option:selected").attr("parentid")); }; </script> </head> <body> <div> <select id="dropLang"> <option selected="selected" value="0">Please Select</option> <option value="1">Javascript</option> <option value="2">Java</option> <option value="3">C#</option> </select> <select id="dropFrame"> <option selected="selected" value="0">Please Select</option> <option value="1" parentid="1">JQuery</option> <option value="2" parentid="1">Prototype</option> <option value="3" parentid="2">Struts</option> <option value="4" parentid="2">Spring</option> <option value="5" parentid="2">Velocity</option> <option value="6" parentid="2">Hibernate</option> <option value="7" parentid="3">ASP.NET MVC</option> <option value="8" parentid="3">Castle</option> </select> </div> </body> </html>
顺便提及下,iframe中对父的操作:
alert("parent:"+$("#currentTenant",window.parent.document).val());//找父亲中的id为currentTenant的value
创建option1:
var option = new Option(tenantArr[0], tenantArr[0]); document.getElementById("curTenantName").add(option);tenantSelect.attr("value", tenantArr[0]);创建option2:
$("#curTenantName").append($("<option selected='selected'/>").val(tenantArr[0]).text(tenantArr[0])).attr("selected","selected");
- option隐藏,创建,对父页面的元素的操作
- JavaScript对select中option的隐藏和显示操作
- jquery对元素隐藏的操作
- SELECT中OPTION元素的显示隐藏
- jquery获取表单元素select option的值,对select option操作
- jquery获得option的值 和对option的操作
- selenium操作隐藏的元素
- selenium操作隐藏的元素
- jquery获得option的值和对option进行操作
- jquery获得option的值和对option进行操作
- jquery获得option的值和对option进行操作
- jquery获得option的值和对option进行操作
- jquery获得option的值和对option进行操作
- 对static页面JS创建元素的理解
- JQuery 对 Select option 的操作
- Jquery 对select option 的操作
- jquery 对select中option的操作
- JQuery 对 Select option 的操作
- 决策树算法解析---ID3,C4.5
- socket资料
- From kernel startup entry point to start_kernel (3)
- 给IT新人的15点建议:苦逼程序员的辛酸反省与总结
- malloc/free and new/delete in C++
- option隐藏,创建,对父页面的元素的操作
- 推荐13款优秀的Twitter Bootstrap JavaScript插件
- CI5.6-交换整数二进制形式中的奇数偶数位
- 把CS值传给JS使用
- Design Pattern: Adapter 模式 - Class Adapter
- C# MediaPlayer循环播放
- ios开发常用的宏
- String,arraylist, hashmap初始化
- 海量数据的存储计算和查询模型