开发者社区 问答 正文

jquery操作select时失败,不明原因

代码如下,实现的是选中我要选的那个text

<html>
<head>
 
   <script type="text/javascript" src="./js/jquery-1.10.2.js"></script>
</head>
<script type="text/javascript">
$("[id='se']").find("option[text='sd']").attr("selected",true);
 
</script>
<body>
<select id="se" name="se">
<option >中国</option>
<option >美国</option>
<option >sd</option>
</select>
</body>
</html>

错在何处了??

展开
收起
a123456678 2016-07-08 16:45:06 2144 分享 版权
1 条回答
写回答
取消 提交回答
  • <html>
    <head>
     
       <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    </head>
    <script type="text/javascript">
    $(document).ready(function(){
    $("#se").find("option[text='sd']").prop("selected",true);
    })
     
     
    </script>
    <body>
    <select id="se" name="se">
    <option text='zg' >中?</option>
    <option text='mg' >美?</option>
    <option text='sd' >sd</option>
    </select>
    </body>
    </html>
    2019-07-17 19:53:40
    赞同 展开评论
问答分类:
问答地址: