【发布时间】:2016-07-27 06:45:27
【问题描述】:
我在同一页面上有多个内容评论框,我无法识别它们以正确处理它们 - 例如,我尝试在哪里发布评论(来自哪个评论框)并不重要 -它总是被发布到页面上的第一个评论框,或者我在发布评论后与输入作斗争以清除但输入仅在同一个第一个评论框上清除。这是我所拥有的: (AJAX)
$(function() {
$(".comm").click(function() {
var parentDiv = $(this).parent('.post_comment').next().children(":first");
var comment = $(this).parent('.post_comment').find('.comment').val();
var name = document.getElementById("username").value;
var idv = $(this).parent('.post_comment').find("#idv").val();
var posthere = $(this).parent().siblings('.wrap_comment').find('#wrap').attr('class');
alert(idv);
if(comment=='')
{
alert("Enter some text..");
$("#content").focus();
}
else
{
$.ajax({
type: "POST",
url: "river_flow.php",
data:
{ username: $("#username").val(),
idv: $(this).parent('.post_comment').find(".idv").val(),
comment: $(this).parent('.post_comment').find('.comment').val()},
cache: false,
success: function(data){
$('#show').after(data);
$(this).find('.comment').css('background-color','red');
$("#content").focus();
}})
return false;
}})})
(HTML)
<div class='com'><button class='click_and_comment'>Give it a comment</button>
<div class='post_comment'>
<img class='end' src="img/end.png" alt='close'/>
<input type="hidden" id="username" value="<?php echo $_SESSION['username'] ?>" name='username'/>
<input type="hidden"class='idv' id="idv" value="<?php echo $row['idv']; ?>" name='idv'/>
<textarea type='text' class="input_comment comment" placeholder='What do you think?' name='comment' id='comment' ></textarea>
<input type='submit' name='comment_submit' class="comment_submit comm" id='comm'/>
</div>
<div class='wrap_comment' id="<?php echo $row['idv']; ?>" >
<div id="show" align="left" class="<?php echo $row['idv']; ?>" ></div>
<?php
$idvc = $row['idv'];
$query = " SELECT * FROM comments WHERE idvc= '$idvc' ORDER BY datec DESC;";
$result = mysqli_query($conn,$query);
while ($bow = mysqli_fetch_assoc($result)) {
echo "<div class='each_comment' id='<?php echo $bow[idvc];?>' >".$bow['commentc']."</div> ";}
?>
</div>
所以,在一个问题中形成我的问题:如何将用户 cmets 分别发布到他们“需要”发布的位置,以及如何仅清理“当前”或“此”输入 - 并不总是首先。再一次 - 一切都很完美,问题是评论框总是不止一个,我需要区分它们并相应地对待它们。这是我的猜测不起作用(矛盾的是我不会在这里),请解释一下,为什么它们不起作用,因为甚至很简单:
$(this).find('#comment').value = '';
不起作用!也许它没有“看到”这个属性。但为什么?!所以。以下是我的猜测:
$(this).parent('.post_comment').siblings('.wrap_comment').find('#show').after(data);
(这是评论帖子,这是我对输入清除的猜测:)
$(this).parent('.post_comment').find('#comment').val('');
我发现了类似的东西:
$('#comment').removeAttr('value');
不起作用 - 我不是在谈论当这些东西不起作用时我得到的纯粹的死胡同:
$(this).find('.comment').css('background-color','red');
哎呀。所以,我希望有人可以为我清除这一切。我是新手说实话。谢谢!
【问题讨论】:
-
好的。请给我链接好吗?
-
谢谢你让我看看我能做些什么来提供帮助
-
你去!请帮我解决这个问题
-
我无法找到您的确切问题所在,是您的 jquery 代码中的某一行吗?
标签: javascript jquery html comments this