Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
280 views
in Technique[技术] by (71.8m points)

javascript - How to refresh jQuery Accordion select menu with a value injected by Tampermonkey

I'm facing a situation with a website with only user accesss. I have a lot of entries to do, and I'm trying to do a script to help me in this task.

The input I want to change :

<select name="vehicleVo[year]" id="vehicleVo_year">
   <option value="" selected="selected">Année</option>
   <option value="2019">2019</option>
   <option value="2020">2020</option>
   <option value="2021">2021</option>
</select>

The Tampermonkey script change the value :

$("#vehicleVo_year").val("2019");

And when selected, the next select menu on the website should update and display stuff linked to the results (in our case: 2019). If I select manually the year 2019, everythings works fine. When I'm using the script, the select menu is showing 2019, but the next menu doesn't update.

Here what I tried already, without errors, but without any change either :

$("#vehicleVo_year").trigger("click");
$("#vehicleVo_year").change();
$("#vehicleVo_year").accordion("refresh");

I'm not sure where the problem come from, any help would be appreciated...


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This wasn't a front-end issue, and the val() + change() was good option.

The next select menu I tried to refresh was triggered by an EventListener calling an ajax request to update with the previous field the user filled.

I managed to do a workaround by re-doing the same ajax call but under my control. Everything works now :)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...