0

我想传递一个要在我的模式中使用的 url,它依赖于adder从我的主 HTML 文档中获取变量。我知道如何将变量传递给模式以用作文本(使用跨度),但不确定如何在链接<a href>标签中使用变量。

我已将每个文档中重要的区域加粗。Javascriptadder从主 HTML 文档中获取变量并将其存储为 URL。

主要 HTML 文档:

<a href = "#myModal" class = "lib" data-toggle="modal" style = "text-align:center; color: #FF761A;" href="/models/{{symbol.id}}/view_model/"><span id = "modelname"> {{symbol.modelname.upper}}</span> - <span id = "format">{{ symbol.format }}</span>**<span id = "adder" style="visibility:hidden;"> {{symbol.adder}}</span>**</a>

JAVASCRIPT:

 <script type="text/javascript">
    $(document).on("click", ".lib", function () {
         var modelname = $('#modelname').text();
         $('#modelnameplaceholder').replaceWith(modelname);     
         var format = $('#format').text();
         $('#formatplaceholder').replaceWith(format); 
         var adder = $('#adder').text();
         $('#adderplaceholder').replaceWith(adder);   
         **var URL = "/profiles/profile/" + adder + "/"**
         $('#urlplaceholder').replaceWith(URL);   
         var type = $(this).closest("ul").attr('id');
         $('#typeplaceholder').replaceWith(type); 
         $('#myModal').modal('show');
    });
   </script>

模态对话框:

<div id="myModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="myModalLabel"><span id="modelnameplaceholder"></span>&nbsp;<span id="typeplaceholder"></span> for <span id="formatplaceholder"></span></h3>
</div>
<div class="modal-body">
<div style="background-image: url({{ STATIC_URL }}pinax/images/placeholder.png); background-repeat:no-repeat;background-position:center center; height: 300px; width: 100%; "></div>
<br>
<div id = "download-button" style="text-align-center">
<a href="{{MEDIA_URL}}{{item.content}}" class="btn btn-success btn-large" type="submit"><i class="icon-download icon-white"></i>&nbsp;Download {{item.type}}</a>
</div>
<br>
<br>
<br>
<div style="position:0px;float:right;">
**Added by <a href = urlplaceholder><span id="adderplaceholder"></span></a>**

我想Added by <username>链接到从 javascript 传递的 url。

我该怎么做?

4

1 回答 1

0

这应该工作

var url = "http://google.com/";
$("#a").href = url;
于 2013-03-31T14:36:58.793 回答