'Kay 很抱歉,这可能是一个简单的问题,还有我的 hacky 代码 :P 但是我已经绞尽脑汁看文档好几个小时了,我正在兜圈子,我的代码基本上是功能性的但我无法从 rec-outlay 标签中选择一个文本值,我不知道为什么。
这是我的 HTML 示例:
<div class='item'>
<p class='issue-title'><strong>Lorem Ipsum</strong></p>
<a class='del-issue' href='#' onclick='document.delIssForm.delIss.value=59;'>Delete</a>
<div class='issue-fix'>
<p>"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad
minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip
ex ea commodo consequat.</p>
<p class='rec-outlay'>40.0</p>
</div>
</div>
<div class='item'>
<p class='issue-title'><strong>Lorem Ipsum</strong></p>
<a class='del-issue' href='#' onclick='document.delIssForm.delIss.value=59;'>Delete</a>
<div class='issue-fix'>
<p>"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad
minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip
ex ea commodo consequat.</p>
<p class='rec-outlay'>40.0</p>
</div>
</div>
当单击删除链接时,jquery 会触发一个确认对话框,这一切功能齐全,除了我尝试从另一个值中减去一个值之外,有人能指出我正确的方向吗?!
$(document).ready(function(){
$('.del-issue').click(function(){
var elem = $(this).closest('.item');
var clicked = {id: $(this).val()};
// var total = $('input[id=CostToSolve]').val();
$.confirm({
'title' : 'Delete Confirmation',
'message' : 'You are about to delete this item. <br />It cannot be restored at a later time! Continue?',
'buttons' : {
'Yes' : {
'class' : 'blue',
'action': function(){
/* elem.slideUp();
var dataString = 'delIss=' + document.delIssForm.delIss.value;
$.ajax({
type: "POST",
url: "delIssue.php",
data: dataString
}); */
// entry is to be deleted catch the value in the outlay box
var total = $("#CostToSolve").val();
// HELP!!!!!
$(this).closest('.item-fix').find('.rec-outlay').text();
total -= (parseInt($(this).text(), 10) || 0);
// Then update the value in the input
$('#CostToSolve').val(total + ".00");
// Prevent script from doing anything further
return false;
}
},
'No' : {
'class' : 'gray',
'action': function(){} // Nothing to do in this case. You can as well omit the action property.
}
}
});
});
});