我在事件上有一个jquery,以便将一些数据传递给bootstrap模态窗口。这是模态的代码:
<div class="modal fade" id="renameFile" tabindex="-1" role="dialog" aria-labelledby="renameFile" aria-hidden="true">
<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="formRenameTitle">rename</h4>
</div>
<div class="modal-body">
<form method="post" th:action="files">
<div class="input-group">
<input type="text" class="form-control" id="fileName" name="fileName" />
<span class="input-group-btn">
<button class="btn btn-default" type="submit">rename</button>
</span>
</div>
<input type="hidden" name="action" value="EDIT" />
<input type="hidden" name="fileId" />
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">close</button>
</div>
</div>
</div>
</div>
这里是按钮的代码(它通常位于网格的单元格中):
<a data-toggle="modal" data-id="${{file.id}}" data-name="${{file.name}}" title="rename" class="open-renameFile" href="#renameFile">
<span class="glyphicon glyphicon-pencil" aria-hidden="true</span>rename
</a>
我正在使用百里香来填充每排细胞。
在页面底部我已经包含了这个javascript:
<script type="text/javascript">
$(document).on("click", ".open-renameFile", function () {
var fileName = $(this).data('name');
$(".modal-body #fileName").val( fileName );
});
$(document).on("click", ".open-renameFile", function () {
var fileId = $(this).data('id');
$(".modal-body #fileId").val( fileId );
});
</script>
答案 0 :(得分:0)
不确定您的代码的重点是什么,因为您实际上没有对val做任何事情?但试试这个:
<script type="text/javascript">
$('.open-renameFile').click(function () {
console.log('Event fired!');
var fileName = $(this).data('name');
$(".modal-body #fileName").val( fileName );
var fileId = $(this).data('id');
$(".modal-body #fileId").val( fileId );
});
</script>