简体   繁体   English

将JS变量放在我的模态的HREF链接中

[英]Place JS Variable in my modal's HREF link

I have a JS variable showing properly in an alert window. 我有一个JS变量在警报窗口中正确显示。 I am trying to place the same value in my href link on the modal that immediately follows the alert. 我试图将相同的值放在紧随警报之后的模式上的href链接中。

On the main page I have a script that shows the value in an alert box - It gets the clicked_id value from here: 在主页上,我有一个脚本在警报框中显示该值-它从此处获取clicked_id值:

<span onclick='executeChildSupport(this.id)'><a href='#' data-toggle='modal'><i class='fa fa-th' aria-hidden='true'></i></a></span>

This is the JS script that catches the clicked_id and shows in the alert box 这是捕获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
  }

Following the alert, a modal is then shown, I am trying to place the "clicked_id" JS variable that was shown in the alert also in the modal's page where there is an HREF string as shown below (where it says "document.write(clicked_id)") 警报之后,将显示一个模式,然后,我试图将在警报中显示的“ 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>

Any suggestions? 有什么建议么?

HERE IS THE MODAL CODE (BODY AREA ONLY - I believe that is all that is needed by the request) 这是模态代码(仅身体区域-我认为这是请求所需要的全部)

<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>

What about this direction? 那这个方向呢?

<a href="javascript:document.write('../_support/tip.php?id='+clicked_id'); target="_blank">LINK</a>

If I've understood your query then you can follow two ways, (all codes below are not absolute working code, these are given for understanding, you may want to change them as you want) 如果我了解您的查询,则可以采用两种方法(以下所有代码都不是绝对的工作代码,这些代码仅供参考,您可以根据需要更改它们)

not-recommended way is to use a global variable then using it in your link example: 不推荐的方法是使用全局变量,然后在链接示例中使用它:

var current_id = null;
......
alert(clicked_id);
current_id = clicked_id;
....

Then doing 然后做

<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>

Recommended Way is to access and change the value of the dom after alert example: 推荐的方法是在警报示例后访问和更改dom的值:

......
alert(clicked_id);
$('#clicked_id').text(clicked_id);
$('#dynamic_link').attr('href', '../_support/tip.php?id='+clicked_id);
$('#supportShare').modal('show');
.....

or you can use a callback after the modal loads 或者您可以在模式加载后使用回调

......
alert(clicked_id);
$('#supportShare').modal('show', function(){
    $('#clicked_id').text(clicked_id);
    $('#dynamic_link').attr('href', '../_support/tip.php?id='+clicked_id);
});
.....

Then changing a bit like: 然后更改如下:

<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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM