我有一堆動態創建的錨標籤。我基本上想調用一個函數,並使用jQuery的slideDown在該錨標籤下顯示該執行函數的內容。每<a>
標籤與id="id"
和每個<a>
標籤有一個<div id="slidedown">
。一下滑一下標籤就不滑動
我正在使用jquery.slideto.min.js。
下面的代碼甚至不會滑落。
$(function() {
$.ajax({
dataType: 'json'
url: '/lists',
success: function (data) {
if (data != null) {
var html = '<ul>';
$.each(data.apis, function (i, item) {
html += '<li class="res">';
html += '<div class="hed"><h2><a id="id" href="/api/' + item + '.json">' + item + '</a></h2></div><div id="slidedown"></div>';
html += '</li>';
});
html += '</ul>';
$('#exDiv').empty();
$('#exDiv').append(html);
}
},
error: function() {
alert('Error');
},
contentType: 'application/json'
});
$(document).on('click','#id', function(e) {
e.preventDefault();
var link = this.href;
$('#slidedown').slideto();
});
});
我看到Uncaught TypeError: Cannot read property 'version' of undefined
我的控制檯上一次我點擊任何<a>
標籤。
這將有助於看到您的HTML,但它聽起來像你有幾個問題。首先是'#a'和'#slideown'元素將被複制,這是無效的,因爲'id'屬性在文檔中必須是唯一的。改爲使用班級。其次,你需要遍歷'this'的引用中的DOM來找到相鄰的'.slidedown'元素並在其上調用'slideto()'。 –
@RoryMcCrossan請檢查,更新 – fscore
謝謝 - 我給你添加了一個答案 –