[英]How to display images when a link is clicked using JQuery, PHP & MySQL?
[英]jQuery - Display a textbox when a link/button is clicked
我正在嘗試為每個評論放置一個回復按鈕,以便當有人單擊該按鈕(例如“回復”)時,將自動出現一個文本框,用戶可以在其中填寫表格。
到目前為止我沒有做太多...
<div id='replycomment' class='reply' onclick='jsReply($comment_id);'>Reply</div>
<div id='showreply'></div>
function jsReply(comment_id) {
var form = '<form id="showReplyForm" action"add_reply.php" method="post">';
form += '<textarea name="replybody" cols="35" rows="2" maxlength="299"</textarea>';
form += '<input type="hidden" name="replybodyId" value="' + comment_id + '" />'
form += '<input type="submit" name="replysubmit" value="Reply"/></form>';
jQuery('#replybody').replaceWith(form); }
有人可以幫我嗎? 不勝感激。 我對將ID從jquery鏈接到php的方式有些困惑...
謝謝
要使代碼正常工作,請執行以下操作: http : //jsfiddle.net/MaqLQ/1/
頭內:
var jsReply = function(comment_id) {
var form = '<form id="showReplyForm" action"add_reply.php" method="post">';
form += '<textarea name="replybody" cols="35" rows="2" maxlength="299"></textarea>';
form += '<input type="hidden" name="replybodyId" value="' + comment_id + '" />';
form += '<input type="submit" name="replysubmit" value="Reply"/></form>';
jQuery('#showreply').replaceWith(form);
}
您在其中一個表格連接的末尾缺少半分號。 您正在查看的是“ replyBody”而不是html中存在的“ showreply”,並且如果您的代碼不是全局的html,則不會為onclick定義。 您還缺少打開textarea標簽的結尾尖括號。
另外,我不知道您的上下文,並且我不在這里進行代碼審查,但除其他事項外……您應該避免在html元素中使用onclick
。
我建議使用jQuery庫。
通過CSS display: none;
隱藏#showreply
display: none;
並將HTML表單放入其中。
$('#replycomment').click(function() {
$('#showreply').show();
});
我還建議將ID更改為類,因為您將有多個實例。
PHP
<div class='reply'>Reply</div>
<form action='add_reply.php' method='POST' class='reply-form'>
<textarea name='replybody'></textarea>
<input type='hidden' name='comment_id' value='<?php echo $comment_id; ?>' />
<input type='submit' value='Reply' />
</form>
CSS
.reply-form {
display: none;
}
使用Javascript
$(".reply").click(function() {
$(this).siblings(".reply-form").show();
$(this).hide();
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.