我想用jquery ajax每点击save按钮时,在对应的div下插入一个投票模板,把数据插入数据库,并显示在页面上
我想用jquery ajax每点击save按钮时,在对应的div下插入一个投票模板,把数据插入数据库,并显示在页面上
怎么区分第一次save投票模板和第二次save的投票模板的字段呢
$(function(){
//Add Vote click
$('#btnAddVote').click(function () {
$('#ivIID').val($('#sIID').html());
$('#addVoteModal').modal('show');
});
//Save Vote click
$('#btnSaveVote').click(function () {
var VoteTitle = $('#ivTitle').val();
$('.votelist').prepend('<div class="votearea" style="background-color:#c5d9f1;"> ' +
'<h4><div class="title" id="voteTitle"> Title:' + VoteTitle + '</div></h4><br><hr>' +
'<label> <input type="radio" name="member" value="agree" />Agree</label>' +
'<label id=agree style="margin-left: 20px;" > 8 </label><br>' +
'<label><input type="radio" name="member" value="against" />Not Agree</label> ' +
'<label id=notagree style=" margin-left: 20px;"> 2 </label><br><br>' +
'<div class="btn btn-info btn-sm" id="voteTitleSubmit" style="margin-left:80px;">Submit</div>' +
'</div>');
//$('#agree').text("20");
//alert($('#voteTitle').val());
$('#addVoteModal').modal('hide');
});
});
@*Vote Area*@
<div class="col-md-4">
<div class="panel panel-primary" id="panelVoteArea">
<div class="panel-heading panel-heading_4">
<p class="panel-title">Vote Area</p>
<div class="btn-group pull-right btn-deatil">
@* <div class="btn btn-info btn-sm">Detail</div>*@
</div>
<div class="clearfix"></div>
</div>
<div class="panel-body">
<table class="table table-bordered">
<tbody>
<tr>
<th>
<button type="button" id="btnAddVote" data-toggle="modal" class="btn btn-sm btn-primary">ADD Vote</button>
</th>
</tr>
</tbody>
</table>
<div class="votelist" id="VoteTemplate">
</div>
</div>
</div>
</div>
@*Vote Modal*@
<div class="modal fade" id="addVoteModal" tabindex="-1" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
<h4 class="modal-title" id="voteDetails">Add Vote</h4>
</div>
<div class="modal-body">
<table id="voteModalTable" class="table table-bordered" style="margin-top: 5px;">
<tbody>
<tr>
<th class="col-md-2">IID</th>
<td class="col-md-4">
<input type="text" class="form-control" id="ivIID" disabled="disabled" />
</td>
</tr>
<tr>
<th class="col-md-2">Vote Title</th>
<td class="col-md-4">
<input type="text" class="form-control" id="ivTitle" /></td>
</tr>
</tbody>
</table>
</div>
<div class="modal-footer">
<div class="row">
<div class="form-group col-md-6">
</div>
<div class="form-group col-md-6">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-default" id="btnSaveVote">Add</button>
</div>
</div>
</div>
</div>
</div>
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
..你是要怎么区分,你可以在全局或是某个对象内维护一个变量用于记录点击次数,或是即时根据你的模板个数去判断是第几个。
我在拼接语句中加了事件和值传过去
function VoteSubmit(VID, IID) {