Tampermonkey选择下拉值。 它没有ID或名称,只是一个类?

我正在为像ConverTo这样的网页编写Tampermonkey代码:
它应该自动选择下拉列表中的第二个选项:

 MP3 MP4 (video)  

,页面完全加载后几秒钟。
但没有任何反应。

我的代码:

 ...... // @match https://www.converto.io/* // @require http://code.jquery.com/jquery-1.11.0.min.js // ==/UserScript== $(document).ready(function(){ setTimout(test(),10000); function test() { $(".format-select").val('mp4'); } })(); 

请帮忙!

请参阅在AJAX驱动的站点上选择并激活正确的控件 。
许多AJAX驱动的控件不能只是改变; 他们还必须接收关键事件,以便页面设置所需的状态。

ConverTo案例中,该选择似乎期望

  1. 点击事件。
  2. 价值变化。
  3. 改变事件。

您将使用这个完整的工作脚本代码发送该序列:

 // ==UserScript== // @name _ConverTo, Automatically select mp4 // @match https://www.converto.io/* // @require http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js // @require https://gist.github.com/raw/2625891/waitForKeyElements.js // @grant GM_addStyle // ==/UserScript== //- The @grant directive is needed to restore the proper sandbox. waitForKeyElements (".format-select:has(option[value=mp4])", selectFinickyDropdown); function selectFinickyDropdown (jNode) { var evt = new Event ("click"); jNode[0].dispatchEvent (evt); jNode.val('mp4'); evt = new Event ("change"); jNode[0].dispatchEvent (evt); } 

同样可以有其他状态序列。