我想在我的網站上的一堆鏈接上創建一個事件監聽器。這些鏈接在一個循環內生成,所以我最終與<a class = "replyButton" id = "replyID"<? echo $x; ?>
等
我試圖使用下面的代碼來揭示一個輸入框,當每個相應的鏈接被點擊,但沒有運氣。我可以在一種情況下使用普通的JS來工作,但不使用JQuery,像這樣外推幾個。任何幫助都會非常棒。
window.onload = function(){
$('.replyButton').each(function(index){
var domElementId = "replyArea" + index;
domElementId.onclick = function() {
var replyFieldHtml = '<div class = "span4" id = "replyTextField"><table><tr><td id = "replyPhoto"><img src = "/assets/img/usr/profile_holder.jpg" /></td><td id = "replyContent"><input type = "text" id = "replyInput" onkeydown="if (event.keyCode == 13) wallReply()" placeholder = "leave a reply..." /></td></tr></table></div>';
document.getElementById('domElementId').innerHTML = replyFieldHtml;
console.log('domElementId');
return false;
}
});
}
編輯:這裏是用來生成HTML環路IM ... $ X = 0; ($ x < 8){ $ x ++; $ r = $ wallarray - $ x;
$postContent = $wall_content['wall_posts'][$x-1];
$postUser = getUserNameById($wall_content['userID'][$x-1]);
?>
<div class = "row">
<div class = "span6">
<div class = "span1" id = "wallPhoto"><img src ="assets/img/usr/profile_holder.jpg></div>
<div class = "span4">
<div class = "span4" id = "wallFeedStyle"><a id = "wallUserLink" href = "#"><b><? echo $postUser; ?></b></a></div>
<div class = "row">
<div class = "span5">
<div class = "span4" id = "userPost"><? echo $postContent; ?></br><p class = "wallsmall"><a href="#" id = "postLike"></i>Like</a> ·<a class = "replyButton" id = "replyButton<? echo $x; ?>" href="#"></i>Reply</a></p></div></div>
</div>
<div class = "row">
<div class = "span5">
</div>
</div>
<div class = "row" id = "replyArea<? echo $x; ?>"></div>
</div>
<?
}
?>
向我們展示您擁有的html。 – Adil
你想在單擊'.replyButton'時顯示輸入框? –
我已經添加了html感謝@Adil和是JAck,或者在單擊回覆按鈕時插入該HTML塊。 – user1953875