【发布时间】:2019-08-15 21:50:49
【问题描述】:
我正在尝试使用 jquery 根据其类名查找文本并进行更改。基本上我有这个结构:
<td class="walletBalance">0.0000 XBT</td>
所以,我正在尝试:
$("tbody").find("tr").each(function() { //get all rows in table
var ratingTd = $(this).find('td.walletBalance’);//Refers to TD element
if (ratingTd.text() == “0.0000 XBT”) {
ratingTd.text(’changed text’);
}
});
我做错了什么?
For more understanding html structure
Specifically what value i'm trying to change
PS:我用的是tampermonkey
// ==UserScript==
// @name testingalarm
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://www.hey
// @grant none
// @require http://code.jquery.com/jquery-latest.js
// ==/UserScript==
(function() {
'use strict';
// Your code here...
$("tbody").find("tr").each(function() {
var ratingTd = $(this).find('td.walletBalance');
if (ratingTd.text() == "0.0000 XBT") {
ratingTd.text('changed text');
}
});
})();
顺便说一句,这个警报正在工作:
// ==UserScript==
// @name testingalarm
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://www.some
// @grant none
// @require http://code.jquery.com/jquery-latest.js
// ==/UserScript==
(function() {
'use strict';
// Your code here...
$(document).ready(function() {
alert('WINNING');
});
})();
PSS:Manaren 回答后
// ==UserScript==
// @name aaaaa
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://www.some
// @grant none
// @require http://code.jquery.com/jquery-latest.js
// ==/UserScript==
(function() {
'use strict';
// Your code here...
$("tbody tr td.walletBalance").each(
function(){
if ($(this).text() == "0.0000 XBT"){
$(this).text("changed text");
}
}
);
})();
【问题讨论】: