我有以下内容:
<span class="label-info">3</span>
Run Code Online (Sandbox Code Playgroud)
我有以下jquery
var replaceit = $(this).closest(':has(.label-info)').find('.label-info').text();
Run Code Online (Sandbox Code Playgroud)
变量的值始终是一个整数,但不总是3:
ie: 1, 2, 3, 4, 5.
Run Code Online (Sandbox Code Playgroud)
我已经尝试了很多方法,无法获得改变的价值.我的最新尝试是:
return $(this).closest(':has(.label-info)').html().replace(replaceit, (replaceit - 1));
Run Code Online (Sandbox Code Playgroud)
我的最终结果是从"lable-info"的当前值中减去1,并用这个新结果切换它.因此,基于3的值的新跨度将成为.
<span class="label-info">2</span>
Run Code Online (Sandbox Code Playgroud)
我该如何实现这一目标?
更新代码更清晰
HTML:
<div>
<span class="lable-info">3</span>
</div>
<div>
<a class="accept_friend">accept</a>
</div>
Run Code Online (Sandbox Code Playgroud)
JavaScript的:
$(document).on("click", "a.accept_friend", function() {
var checkValue = $(this).closest(':has(.name)').find('.name').text();
var removeit = $(this).closest(':has(.item)').find('.item').fadeOut();
var replaceit = $(this).closest(':has(.label-info)').find('.label-info').text();
$.ajax({
url: '/includes/accept_friend.php',
type: 'post',
data: {checkValue},
success:function(data){
return removeit;
$("a.remove_pending").text(function () {
return ('.label-info').html().replace(replacei, replaceit);
});
}
Run Code Online (Sandbox Code Playgroud)
笔记:
我没有使用id.我正在上课.有多个具有相同名称的类.所以我必须通过最近的电话.
从跨度中获取一个值,将其减去 1 并更新跨度(使用 jQuery):
超文本标记语言
<span class="label-info">3</span>
Run Code Online (Sandbox Code Playgroud)
jQuery
var n = $(".label-info").text(),
n2 = n - 1;
$(".label-info").text(n2);
Run Code Online (Sandbox Code Playgroud)
希望有一点帮助
| 归档时间: |
|
| 查看次数: |
66 次 |
| 最近记录: |