当我点击'icon-remove-sign'时,我试图从'quickCost'获取课程中的价值。我可以使用下面的jQuery获取所有的html,但我不知道如何从那里获取类'quickCost'来抽象值。
在这种情况下,我希望得到33.33美元的金额。我的jQuery代码只输出html。我相信我很亲密。谢谢你的任何提示。
<div class="quickItem">
<i class="icon-remove-sign" id="1457494010"></i>1 CD<div class="quickCost">$33.33</div>
</div>
的jQuery
$( '.icon-remove-sign' ).click(function() {
var theCost = $( $(this).parent() ).html();
console.log(theCost); // Outputs all html in parent div
});
答案 0 :(得分:1)
使用.next()
:
$('.icon-remove-sign').click(function() {
var theCost = $(this).next('div.quickCost').text();
console.log(theCost); // Outputs $33.33
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="quickItem">
<i class="icon-remove-sign" id="1457494010">x</i>1 CD
<div class="quickCost">$33.33</div>
</div>
&#13;
答案 1 :(得分:0)
您也可以使用.parent()
$('.icon-remove-sign').click(function() {
var theCost = $(this).parent().find('.quickCost').text();
console.log(theCost); // Outputs the text in .quickCost
});
答案 2 :(得分:0)
您可以使用.siblings()
并将ng-model
更改为for (int i = 0; i < c.length; i++) {
int y = 0;
if (i == 0 || i == 10 || i == 20 || i == 30 || i == 40 || i == 50 || i == 60 || i == 70 || i == 80 || i == 90
|| i == 100 || i == 110 || i == 120 || i == 130 || i == 140 || i == 150 || i == 160 || i == 170
|| i == 180 || i == 190 || i == 200 || i == 210 || i == 220 || i == 230 || i == 240 || i == 250
|| i == 260 || i == 270 || i == 280 || i == 290 || i == 300 || i == 310 || i == 320 || i == 330
|| i == 340 || i == 350 || i == 360 || i == 370 || i == 380 || i == 390 || i == 400 || i == 410
|| i == 420 || i == 430 || i == 440 || i == 450 || i == 460 || i == 470 || i == 480 || i == 490
|| i == 500 || i == 510 || i == 520 || i == 530 || i == 540 || i == 550 || i == 560 || i == 570
|| i == 580 || i == 590 || i == 600) {
u[y] = (String) c[y].getSelectedItem();
read.println();
read.print(u[y]);
y = y + 10;
} else {
s = (String) c[i].getSelectedItem();
read.print(s);
}
,以获取.html()
.text()
&#13;
div
&#13;