我正在尝试使用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: Im正在使用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");
}
}
);
})();发布于 2019-03-26 00:01:19
我会试一试,我在浏览器中测试了它,它工作正常。
$("tbody tr td.walletBalance").each(
function(){
if ($(this).text() == "0.0000 XBT"){
$(this).text("changed text");
}
}
);问题:
时可能会出现一些问题
发布于 2019-03-25 23:48:32
这个问题是因为您使用了无效的单引号和双引号字符。单引号应该是',而不是’;双引号应该是",而不是“或”。一旦解决了这个问题,你的代码就能正常工作:
$("tbody").find("tr").each(function() {
var ratingTd = $(this).find('td.walletBalance');
if (ratingTd.text() == "0.0000 XBT") {
ratingTd.text('changed text');
}
});<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table>
<tr>
<td class="walletBalance">0.0000 XBT</td>
</tr>
</table>
https://stackoverflow.com/questions/55341459
复制相似问题