JS获取select的HTML,并获取当前的选中

    技术2022-07-12  80

    <!DOCTYPE> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" /> <meta name="keywords" content="" /> <meta name="description" content="" /> <title>待办事项</title> <link rel="shortcut icon" href="images/favicon.ico" /> <link rel="stylesheet" type="text/css" href="style/base.css" /> <link rel="stylesheet" type="text/css" href="style/common.css" /> </head> <body> <select name="post_address_1"> <option value="">选择地区</option> <volist name="area_list" id="vo"> <option value="{$vo.id}">{$vo.name}</option> </volist> </select> <script> /** * 获取select的HTML内容,并获取选中信息 */ function set_select() { var address_1 = $("select[name='post_address_1']").val(); $("select[name='post_address_1'] option").each(function(index,ele){ if(ele.getAttribute('value') == address_1){ $(ele).attr("selected",true); }else{ $(ele).attr("selected",false); } }); var post_address_1 = $("select[name='post_address_1']").html(); console.log(post_address_1); } </script> </body> </html>

     

    Processed: 0.011, SQL: 9