选择指定文本值、input子元素

   //选择含有文本123div将其背景色变为红色 

 <script type="text/javascript">

            $(document).ready(function(){

                $("#btn1").click(function(){

                    //选择含有文本123div将其背景色变为红色

                    $("div:contains('123')").css("background-color","red");

                });

            });

        </script>

        </head>

 

        <body>

            <div>

                123

            </div>

            <input type="button" id="btn1" value="按钮">

        </body>

 

  //选择含有input子元素的div 将其背景色改为红色

 <script type="text/javascript">

            $(document).ready(function(){

                $("#btn1").click(function(){

                    //选择含有input子元素的div 将其背景色改为红色

                    $("div:has('input')").css("background-color","red");

                });

 

            });

        </script>

        </head>

 //遍历所有隐藏的input元素的值  each是进行遍历的方法

 <script type="text/javascript">

            $(document).ready(function(){

                //遍历所有隐藏的input元素的值  each是进行遍历的方法

                $("#btn1").click(function(){

                    $("input:hidden").each(function(){

                        alert($(this).val());

                    });

                });

 

            });

        </script>

        </head>

 

        <body>

            <input type="hidden" value="1">

            <input type="hidden" value="2">

            <input type="hidden" value="3">

            <input type="button" id="btn1" value="按钮1">

        </body>

 

        <body>

            <div>

                <input/>

            </div>

            <input type="button" id="btn1" value="按钮">

        </body>

posted on 2019-02-22 17:09  城市小农民  阅读(180)  评论(0编辑  收藏  举报

导航