我有这部分代码代表这一系列项目: http://www.gosu.cz
<script> //this script is used to set A TAG href via it's ID
$(document).ready(function() {
$('img').click(function () {
var alt = $(this).attr("alt")
var strLink = "link&Key=" + alt;
document.getElementById("link").setAttribute("href",strLink);
});
});
<!-- Least Content -->
<main id="least">
<div class="container-fluid">
<div class="least-preview"></div> //div used to show selected item
<ul class="gallery start" id="gallery_w">
<!-- item -->
//definition of item, which carry additional informations in data-caption
//However having A TAG using ID to set HREF does't work when ID is not in ""
<li class="item col-xs-12 col-sm-6 col-md-4">
<a href="http://placehold.it/857x712" data-caption="<h3>Header</h3> <p>description </p> <a id=link>Zobrazit produkty</a>" />
<img src="http://placehold.it/857x712" class="img-responsive" alt="chair" />
</a>
</li>
<!-- /item -->
如果您点击我现在正在处理的第一项(http://imgur.com/a/VdKQK),您可以看到显示的数据标题(可在此代码中看到)。我需要的是通过id使A TAG工作。当它在标签参数之外使用时它通常工作,但我不能在参数内运行它。请问我的语法错误在哪里?