javascript - 将值传递到 Bootboxjs 对话框确认框
问题描述
我有一个PHP
这样的 foreach 循环:
<?php
foreach ($student->student as $d) {
echo
'<tr>'
'<td class="StudentID">' . $d->ID . '</td>' .
'<td>' . $d->Date . '</td>' .
'<td>' . $d->Name . '</td>' .
'<td><a class="show-confirmation">'. "click to confirm" . '</a></td>' .
'</tr>';
}
?>
我正在使用这样bootbox js
的对话框:
<script>
$(document).on("click", ".show-confirmation", function(e) {
var StudentID = $('#StudentID').val();
bootbox.confirm("Confirm, student ID? " + StudentID, function(result) {
console.log('This was logged in the callback: ' + result);
console.log('StudentID: ' + StudentID);
});
});
</script>
我想要完成的是当我单击click to confirm
which has时class="show-confirmation"
,我想$d->ID
在bootbox js
确认对话框中获取 的值。由于这是一个for each
循环,我想每次在对话框确认框上传递一个新的学生 ID。
在确认对话框中,我想查看Confirm, student ID? + 15
该行的学生 ID。
我做了什么?
- 我添加了一个变量
var StudentID = $('#StudentID').val();
,希望从类中获取学生 ID 值,StudentID
例如:<td class="StudentID">
但它是undefined
在我访问它的时候。
有人可以指导我完成这个方法吗?
解决方案
您$('#StudentID')
正在寻找一个将其设置为类的 id 属性的元素。改为$('.StudentID')
改为。
推荐阅读
- java - 在 JTextArea 中添加动态文本值
- java - Java - 使用客户端证书身份验证时取消 Ssl 流
- jax-rs - Bean 验证是否适用于语义或语法?
- google-search - 谷歌搜索 - 创建后立即制作谷歌索引个人资料页面
- javascript - 创建自定义 URL 以触发按钮
- python - 是否可以将列表导出到 .txt 以便记事本可以读取换行符?
- elasticsearch - lucene查询使用grafana替换子字符串
- google-apps-script - Google Apps 脚本在 for 循环中神秘地停止运行
- javascript - 如何调用存在于 2 个 js 文件中的 js 方法?
- sapui5 - 从 TableSelectDialog 到表单的数据绑定