How can I select an element by ID with jQuery using regex?

前端 未结 7 1635
执念已碎
执念已碎 2020-11-28 05:51

I have the following input elements:




        
相关标签:
7条回答
  • 2020-11-28 06:52

    How about this :

    <!DOCTYPE html>
    <html>
    <head>
        <title></title>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
        </head>
        <body>
            <input id="AAA_RandomString_BBB" type="text" />
            <input id="AAA_RandomString_BBB_Start" type="text" />
            <input id="AAA_RandomString_BBB_End" type="text" />
    
            <script>
                $(document).ready(function () {
                    debugger
                    var targetElement = $('input')
                    .filter(function () {
                        var el = this.id.match(/^AAA.*BBB$/g);
                        return el;
                    });
                    console.log(targetElement.val());
                })
            </script>
        </body>
    </html>
    
    0 讨论(0)
提交回复
热议问题