![](/img/trans.png)
[英]How can I make a button a loading button as long as the function is executed?
[英]When loading an array of photos, how can I make a unique comment button function for each imageID?
HTML
<textarea required=required name ="comment" id="comment"></textarea><br/>
<input type="hidden" id="image" name ="image" value="<?php echo $images[$i]['imageID']?>" />
<input type=button id=postComment value="Post Comment">
commentImage.js $(document).ready(function(){
$('#postComment').click(function(){
$.ajax({
type:'post',
url:'commentImage.php',
data:{newComment:$('#comment').val(), postID:postID},
success:function(data){
var data = JSON.parse(data);
var comment = makeComment(data['user'], $('#comment').val(), data['date']);
$('#commentsBock').prepend(comment);
$('#comment').val('');
}
})
})
})
function makeComment(user, comment, date){
var comment = '<div><div>'+user+'</div><div>'+comment+'</div><div>'+date+'</div><div>';
return comment;
}
function getComments(){
}
commentImage.php
<?php
session_start();
echo $_POST['comment'];
echo $_POST['image'];
include_once('mysql.php');
...
?>
#comment
是一個唯一的ID。 如果您在HTML中多次使用它,請不要等待它正常工作,它不會!
只需使用您的PostID,如id="comment_"+PostID
即可創建唯一標識符。 並使用$("input[id^='comment_']")
來選擇id以comment_
開頭的所有ID (這就是^=
做的)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.