2017-06-19 49 views
0

我有一个JS变量在警告窗口中正确显示。我试图在紧跟在警报之后的模式的href链接中放置相同的值。在我的模式的HREF链接中放置JS变量

在主页上我有一个脚本,显示一个警告框的值 - 它从这里获取clicked_id值:

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

这是JS脚本映入clicked_id,并显示在警报箱

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> 

有什么建议吗?

这里是模态码(BODY地区唯一 - 我相信这是一个由请求所需要的全部)

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

''没有任何ID? – Bergi

+0

“#supportShare”模式中的确切位置是您想要更改的链接?请发布完整的模式标记。然后,只需使用适当的选择器来定位元素并设置其文本即可。 – Bergi

+0

但是,警报显示每个列出项目的正确ID?我只需要身份证即可继续使用该模式,以便将其放入链接中。链接实际上按照常规约定http:// link?id = XXX启动不同的PHP页面。这是我需要的XXX。 – Davo

回答

1

如果我理解您的查询,那么你可以按照两种方式, (下面的所有代码都不是绝对的工作代码,这些是理解给定的,你可能要改变他们,只要你想)

不推荐的方式是使用全局变量,然后用它在你的链接 例如:

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

正确的ID显示在SPAN区域中,但未添加到“../_support/tip.php?id=”?我需要它ro输出“../_support/tip.php?id=22017”--- 22017是SPAN输出(我也想这样做推荐的方式:-)谢谢你的耐心 – Davo

+0

编辑我的答案,希望帮助:) –

+0

它的作品!!!!!!优秀 - 我使用了第一个选项(不是模态中的回调)... – Davo