jQuery操作select

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>jquery操作select</title>
    <script type="text/javascript" src="../js2/jquery-1.7.2.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            //修改option中的内容
            //$("#select option:first").html("被修改了");

            //获取被选中的option中的内容
            // $("#click").click(function () {
            //     alert($("#select").find("option:checked").text());
            //     alert($("#select option:checked").text());
            //
            // });

            // 获取被选中的option中值
            // $("#click").click(function () {
            //     alert($("#select option:checked").val());
            //
            // })


            // $("#click").click(function () {
            //     获取Select选择的索引值
            //     alert($("#select").get(0).selectedIndex);
            //
            // });

            //Select追加一个Option(下拉项)
            // $("#click").click(function () {
            //     $("#select").append("<option value='zhengzhou'>郑州</option>");
            //
            // })

            //Select插入一个Option(第一个位置)
            // $("#click").click(function () {
            //     $("#select").prepend("<option value='zhengzhou'>郑州</option>");
            //
            // })

            //删除SelectValue='beijing'Option
            // $("#click").click(function () {
            //     $("#select option[value='beijing']").remove();
            //
            // });


            // $("#click").click(function () {
            //     //内容清空:
            //     $("#select").empty();
            // });

        });




    </script>
</head>
<body>
<input id="click" type="button" value="点击">
<select id="select" name="city">
    <option value="beijing">北京</option>
    <option value="shanghai">上海</option>
    <option value="guangzhou">广州</option>
</select>
</body>
</html>

$(".select")
        .change(
                function () {
                    var newssorts = $(this).find("option:selected").val();
                    window.location.href = "${request.contextPath}/admin/news_all?newssorts=" + newssorts;
                });




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值