Changing the normal binding event to a static element to a dynamic element binding event will be used in the following way:The simple thing is to bind the event to the parent element of the binding element, which indicates which element under the parent element to bind to, so that regardless of whether your element is new, there are bound events, and the code is as follows:
<div class= "Btn-group listtype" > <button id= "ListType" class= "btn" value= "style=" min-width:280px;_ width:280px; "data-toggle=" dropdown ">== Please select ==</button> <button class=" Btn Dropdown-toggle " Data-toggle= "dropdown" ><span class= "caret" ></span></button> <ul id= "Listtype_ul" class= "Dropdown-menu" style= "min-width:300px;_width:300px;" > <li><a href= "javascript:void (0)" value= "1001" > Menu 1</a></li> <li><a href= "javascript:void (0)" value= "1002" > Menu 2</a></li> </ul></div>
To bind the final bind event of the A element, but here a is loaded with a dynamic load, so we have to bind class= "Dropdown-menu" ul first, then the on event 2nd parameter indicates a element
$ (". ListType. Dropdown-menu"). On ("Click", "a",function() { $ ("#listType"). Text ($ (This ). Text ()); $ ("#listType"). attr ("Value", $ (this). attr ("value"));})
jquery Dynamic binding elements