[英]Place JS Variable in my modal's HREF link
我有一個JS變量在警報窗口中正確顯示。 我試圖將相同的值放在緊隨警報之后的模式上的href鏈接中。
在主頁上,我有一個腳本在警報框中顯示該值-它從此處獲取clicked_id值:
<span onclick='executeChildSupport(this.id)'><a href='#' data-toggle='modal'><i class='fa fa-th' aria-hidden='true'></i></a></span>
這是捕獲clicked_id並顯示在警報框中的JS腳本
function executeChildSupport(clicked_id) {
$(this).tooltip('hide');
event.currentTarget.innerHTML = "<i class='fa fa-th' aria-hidden='true' style='margin-left:10px'></i>";
alert(clicked_id);
$('#supportShare').modal('show');
return false
}
警報之后,將顯示一個模式,然后,我試圖將在警報中顯示的“ clicked_id” JS變量也放置在模式的頁面中,該頁面中有一個HREF字符串,如下所示(其中說“ document.write( clicked_id)“)
<a href="../_support/tip.php?id=" target="_blank" class="btn btn-primary"><i class='fa fa-money fa-3x' aria-hidden='true' style="padding-bottom:3px"></i><br>LINK HERE <script>document.write(clicked_id);</script></a>
有什么建議么?
這是模態代碼(僅身體區域-我認為這是請求所需要的全部)
<div class="modal-body" style="padding: 40px;color:#fff">
<table border="0" style="width:100%">
<tr>
<td colspan="3" style="padding:8px 3px 3px 2px">
<a href="../_support/tip.php?id=" target="_blank" class="btn btn-primary" style="background-color:#171717;width:100%;border:none;padding:30px">
<i class='fa fa-money fa-3x' aria-hidden='true' style="padding-bottom:3px"></i><br>LINK <script>document.write(+clicked_id+);</script></a>
</td>
</tr>
</table>
</div>
那這個方向呢?
<a href="javascript:document.write('../_support/tip.php?id='+clicked_id'); target="_blank">LINK</a>
如果我了解您的查詢,則可以采用兩種方法(以下所有代碼都不是絕對的工作代碼,這些代碼僅供參考,您可以根據需要更改它們)
不推薦的方法是使用全局變量,然后在鏈接示例中使用它:
var current_id = null;
......
alert(clicked_id);
current_id = clicked_id;
....
然后做
<a href="../_support/tip.php?id=" target="_blank" class="btn btn-primary">
<i class='fa fa-money fa-3x' aria-hidden='true' style="padding-bottom:3px"></i>
<br>
LINK HERE
<script>document.write(current_id);</script>
</a>
推薦的方法是在警報示例后訪問和更改dom的值:
......
alert(clicked_id);
$('#clicked_id').text(clicked_id);
$('#dynamic_link').attr('href', '../_support/tip.php?id='+clicked_id);
$('#supportShare').modal('show');
.....
或者您可以在模式加載后使用回調
......
alert(clicked_id);
$('#supportShare').modal('show', function(){
$('#clicked_id').text(clicked_id);
$('#dynamic_link').attr('href', '../_support/tip.php?id='+clicked_id);
});
.....
然后更改如下:
<a href="#" target="_blank" class="btn btn-primary" id="dynamic_link">
<i class='fa fa-money fa-3x' aria-hidden='true' style="padding-bottom:3px"></i>
<br>
LINK HERE
<span id="clicked_id"></span>
</a>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.