joymis Posted May 14, 2018 Share Posted May 14, 2018 (edited) Hello, I have this code <button class="btn btn-info" onclick="BatchAsign()">Batch</button> <button class="asign_btn" onclick="Asign({a:'1', b:'2'}, this)">Asign1</button> <button class="asign_btn" onclick="Asign({a:'2', b:'6'}, this)">Asign2</button> <button class="asign_btn" onclick="Asign({a:'5', b:'4'}, this)">Asign3</button> <script> function BatchAsign(){ $.each( $('.asign_btn'), function( key, val ) { $(this).trigger( "click", ['all'] ) }); } function Asign(arr, dom, x) { if(x == 'all'){ // I want do something } } </script> When I click BatchAsign button, I want pass a extra parameters to Asign. I used console.log(x), it's display 'undefined'. How can I get string 'all' in the function Asign? thanks. Edited May 14, 2018 by joymis Link to comment Share on other sites More sharing options...
justsomeguy Posted May 14, 2018 Share Posted May 14, 2018 The jQuery documentation for trigger seems to imply that you need to use the on method or one of its shortcuts to assign the event handler. That might mean it's not going to work correctly by using event attributes. Link to comment Share on other sites More sharing options...
dsonesuk Posted May 14, 2018 Share Posted May 14, 2018 Use a custom data- attribute on 'asign_btn' class to add to and store the value 'all' when batch button clicked, then use dom parameter to retrieve that value from that specific data attribute. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now