简体   繁体   中英

jq event fire only on page load

I have following things happening on page load

select option has a value , based on first select option, second selection option receives it value.

After above events, search click event is invoked.

Now the problem is, even when first select option is changed, search click event is carried.How is the way so that, search click events gets fired only once ie on page load and not on other times that is first select option value change.

No codes, I want to know, if there is any way it can be achieved, there must be.

Yes, it can be acheived. Either disable the button and just enable it when the select value of desired select is changed, or, if you don't want to disable the button - add change event to every select. Keep a variable last_select_changed to keep track of which selected was the last one to get changed. When the button is clicked, check the variable value and see if that's the select that you wanted to get changed. You can store the select's id in the button to keep a track with uniqueness.

$.one( events [, data ], handler(eventObject) ) Method will help you. One method can be defined with any element. I executed evet at most one per element.

for more information you can visit click here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM