簡體   English   中英

使用Greasemonkey更改類別值?

[英]Change Class value using Greasemonkey?

哪種方法使用Greasemonkey更改類值? 例如,我想更改:

<a id="Test" class="button_primary button_left_padding tlignore disabled" role="button"

至:

<a id="Test" class="button_primary button_left_padding tlignore enabled" role="button"

對於簡單的靜態頁面,並假設id="Test"是唯一且穩定的,則類似以下代碼的代碼將起作用:

var targNode    = document.getElementById ("Test");
targNode.classList.remove ("disabled");
targNode.classList.add ("enabled");


對於AJAX驅動的頁面,此完整腳本將起作用:

// ==UserScript==
// @name     _Flip CSS classes
// @match    http://YOUR_SERVER.COM/YOUR_PATH/*
// @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 ("#Test", swapClass);

function swapClass (jNode) {
    jNode.removeClass ("disabled").addClass ("enabled");
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM