我有一个名为view的按钮。单击视图按钮时,应弹出一个模态窗口,其中包含给定值
下面是视图按钮的代码,它弹出一个带有空体的模态。
<a role="button" class="btn btn-sm btn-primary" href="#time_line" data-toggle="modal">View</a>
模态div:
<div id="time_line" class="modal fade" tabindex="-1">
<div class="modal-header" style="background: #045e9f;">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="white bigger">Initiate Order</h4>
</div>
<div class="modal-body overflow-visible">
<form>
<input type="text" name="t_val" id="t_val">
</form>
</div>
<div class="modal-footer">
<button class="btn btn-small" data-dismiss="modal">
<i class="icon-remove"></i>
Close
</button>
</div>
</div>
如何在模态弹出
上将值传递给模态中的val字段答案:
嗨,我做了以下事情,得到了我想要的东西
function pass_data(data)
{
$('[name="t_val"]').val(data);
}
<a role="button" class="btn btn-sm btn-primary" href="#time_line" data-toggle="modal" onclick= "pass_data($data)">View</a>
DarkseidNG对答案略有改动
答案 0 :(得分:1)
创建一个javascript函数并将值从onClick传递给函数,然后在函数中调用你的模态
<a role="button" class="btn btn-sm btn-primary" href="#time_line" onclick = "doFunction('<?php echo $xyz; ?>')">View</a>
<script>
function doFunction(data){
//if you have a html tag in the modal that you want to pass the value to you can do this
$(".data-tag").html(data);
$("#time_line").modal();
}