问问题
3482 次
2 回答
2
好的,试试这个:
var opt = document.createElement("option");
var content = document.createTextNode("PU (unrated)");
opt.appendChild(content);
var attr = document.createAttribute("value");
attr.nodeValue = "pu";
opt.setAttributeNode(attr);
var targetEl = document.getElementById("lobby-format");
targetEl.appendChild(opt);
这只会增加一个选项,但我想你明白了。
于 2012-06-03T20:26:48.340 回答
0
这是一个脚本,它使用 jQuery 的强大功能在目标点添加选项(在 jsBin测试):
// ==UserScript==
// @name _Add new options at select points
// @include http://play.pokemonshowdown.com/*
// @include http://jsbin.com/azeveh*
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
// ==/UserScript==
var selectNode = $("#lobby-format");
selectNode .find ("option[value='nu']")
.after ('<option value="pu">PU (unrated)</option>');
selectNode .find ("option[value='lc']")
.after ('<option value="bwcup">BW Cup (unrated)</option>');
OP 的特定站点使用 AJAX 来添加<select>
. 要补偿 AJAX,请使用该waitForKeyElements
实用程序。像这样:
// ==UserScript==
// @name _Add new options at select points, AJAX compensated.
// @include http://jsbin.com/azeveh*
// @include http://play.pokemonshowdown.com/*
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
// @require https://gist.github.com/raw/2625891/waitForKeyElements.js
// ==/UserScript==
waitForKeyElements ("#lobby-format option[value='nu']", AddOption_1);
waitForKeyElements ("#lobby-format option[value='lc']", AddOption_2);
function AddOption_1 (jNode) {
jNode.after ('<option value="pu">PU (unrated)</option>');
}
function AddOption_2 (jNode) {
jNode.after ('<option value="bwcup">BW Cup (unrated)</option>');
}
于 2012-06-03T20:46:31.200 回答