jQuery - 打开一个 URL 和 select 一个值
jQuery - Open a URL and select a value
使用 GreaseMonkey,查找 select 一个值并在页面加载后点击提交按钮。让我们以 False/No 为例
window.addEventListener ("load", LocalMain, false);
function LocalMain () {
$('select[name=timeEnabled]').val(1);
$('input[type=submit]')[0].click();
}
<select name="timeEnabled" onchange="timeUpdated()" class="alignLeft nowrap">
<option value="true" selected="selected">Yes</option>
<option value="false">No</option></select>
<input name="submit" value="Apply" onclick="return preSubmit()" class="btn btn-small btn-primary" type="submit">
听起来您正在寻找的是一个浏览器插件,它将在页面加载时执行脚本。查看 Greasemonkey https://addons.mozilla.org/en-US/firefox/addon/greasemonkey/
在 Firefox 中安装该插件,编写您的 JavaScript 来操作相关的表单元素并提交表单(查看他们的文档 here)。然后打开所有编辑链接。
是的,您可以使用 .val(optionIndex)
手动 select 一个值。然后你可以通过.click()
.
手动点击应用按钮
$('select[name=timeEnabled]').val(1); // Select the 'No' option for example.
$('input[type=submit]')[0].click(); // Click the button, use [0] to use the native JS function instead of the jQuery one (which is used for handling onclick events).
对于 GreaseMonkey,我怀疑这是有效的。这是一个 jsFiddle 示例:https://jsfiddle.net/Twisty/xtmpca4b/
HTML
<form>
<select name="timeEnabled" onchange="timeUpdated()" class="alignLeft nowrap">
<option value="true" selected="selected">Yes</option>
<option value="false">No</option>
</select>
<input name="submit" value="Apply" onclick="return preSubmit()" class="btn btn-small btn-primary" type="submit">
</form>
GreaseMonkey
// ==UserScript==
// @name Apply Each Tab
// @date 01/27/2016
// @require https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js
// @namespace http://www.your-url-target.com/page-target.html
// @description Select a value from an element and submit the parent form.
// @version 0.1
// @grant none
// ==/UserScript==
$(document).ready(function() {
$("select[name='timeEnabled']").val("false");
$("input[type='submit']")[0].click();
});
确保更新您的 @namespace
以匹配目标 URL。使用 .ready()
将导致在加载页面时执行 JQuery。
您可能还想考虑:
$("select[name='timeEnabled']").val("false").parent("form").submit();
使用 GreaseMonkey,查找 select 一个值并在页面加载后点击提交按钮。让我们以 False/No 为例
window.addEventListener ("load", LocalMain, false);
function LocalMain () {
$('select[name=timeEnabled]').val(1);
$('input[type=submit]')[0].click();
}
<select name="timeEnabled" onchange="timeUpdated()" class="alignLeft nowrap">
<option value="true" selected="selected">Yes</option>
<option value="false">No</option></select>
<input name="submit" value="Apply" onclick="return preSubmit()" class="btn btn-small btn-primary" type="submit">
听起来您正在寻找的是一个浏览器插件,它将在页面加载时执行脚本。查看 Greasemonkey https://addons.mozilla.org/en-US/firefox/addon/greasemonkey/
在 Firefox 中安装该插件,编写您的 JavaScript 来操作相关的表单元素并提交表单(查看他们的文档 here)。然后打开所有编辑链接。
是的,您可以使用 .val(optionIndex)
手动 select 一个值。然后你可以通过.click()
.
$('select[name=timeEnabled]').val(1); // Select the 'No' option for example.
$('input[type=submit]')[0].click(); // Click the button, use [0] to use the native JS function instead of the jQuery one (which is used for handling onclick events).
对于 GreaseMonkey,我怀疑这是有效的。这是一个 jsFiddle 示例:https://jsfiddle.net/Twisty/xtmpca4b/
HTML
<form>
<select name="timeEnabled" onchange="timeUpdated()" class="alignLeft nowrap">
<option value="true" selected="selected">Yes</option>
<option value="false">No</option>
</select>
<input name="submit" value="Apply" onclick="return preSubmit()" class="btn btn-small btn-primary" type="submit">
</form>
GreaseMonkey
// ==UserScript==
// @name Apply Each Tab
// @date 01/27/2016
// @require https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js
// @namespace http://www.your-url-target.com/page-target.html
// @description Select a value from an element and submit the parent form.
// @version 0.1
// @grant none
// ==/UserScript==
$(document).ready(function() {
$("select[name='timeEnabled']").val("false");
$("input[type='submit']")[0].click();
});
确保更新您的 @namespace
以匹配目标 URL。使用 .ready()
将导致在加载页面时执行 JQuery。
您可能还想考虑:
$("select[name='timeEnabled']").val("false").parent("form").submit();