爲了實現這一目標頁面(很抱歉,但SO不允許超鏈接62.0.54.118):如何在AJAX驅動的頁面中更改<input>的名稱字段?
http://62.0.54.118/search?&q=42&oq=42&sourceid=chrome&ie=UTF-8&filter=0
,我想用默認用userscript改變一個<input>
的名稱字段。
輸入是:
<input class="gsfi" id="lst-ib" name="q" maxlength="2048" value="42"...>
我想將它更改爲:
<input class="gsfi" id="lst-ib" name="&q" maxlength="2048" value="42"...>
也就是說,我希望將q
變成&q
由name
領域的投入默認。
我試着寫一個腳本,(即不工作):
// ==UserScript==
// @name Normal Google Input
// @include http://62.0.54.118/*
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js
// @require https://gist.github.com/raw/2625891/waitForKeyElements.js
// @grant GM_addStyle
// ==/UserScript==
/*- The @grant directive is needed to work around a design change
introduced in GM 1.0. It restores the sandbox.
*/
waitForKeyElements ("input[name*='q']", changeLinkQuery);
function changeLinkQuery (jNode) {
var oldName = jNode.attr ('name');
var newName = oldName.replace (/\q/, "&q");
jNode.attr ('name', newName);
return true;
}
此外,該頁面是一個Ajax驅動的頁面。
請修復我的壞腳本或幫我寫另一個, 謝謝。
更新: 我解決了其中的一部分通過改變行我的腳本:
var newName = oldName.replace (/\q/, "&q");
到
var newName = oldName.replace (/q/, "&q");
,然後我的腳本工作得更好。感謝@Gerard Sexton提出的建議。
但現在有一個新的bug,waitForKeyElements
回調設置爲return true;
爲頁面的AJAX,它增加了&
不停止。
它會導致這個領域是name="&&&&&&&&&q"
等
我怎樣才能解決呢?
改變你的正則表達式/ Q/ –
感謝,它做的伎倆 – reemar
我做到了,但我仍然有腳本錯誤: 的'返回true;',爲Ajax使'&'與加不停是什麼導致這個字段爲'name =「&&&&&&&&&&&&」「 – reemar