Если в вашем текстовом поле есть атрибут id
или class
, я бы использовал его, чтобы определить, является ли он видимым / скрытым / уже загруженным и основываясь на этом скрытии / показе / загрузке.
Например, скажем, у текстового поля есть идентификатор reply
, который вы можете сделать:
jQuery('.reply-button').live('click', function() {
// Check if the textbox is on the page or if we need to load it via an ajax call
if (jQuery('#reply').length == 0)
{
// The textbox isn't loaded on the page so call the ajax and append it
var a = jQuery(this).data('comment_id');
var b = jQuery(this).data('video_id');
var c = jQuery(this).data('comment_quote');
var d = jQuery(this).data('reply_name');
var e = jQuery(this).data('quote_body');
var f = jQuery(this).data('topic_name');
var thiss = this;
jQuery.ajax({
type: "POST",
url: "<?= $this->Html->url(array('controller' => 'comments', 'action' => 'reply')); ?>",
data: { comment_id: a, video_id: b, comment_quote: c, reply_name: d , quote_body: e , topic_name: f },
success: function(html) {
thiss.parent().parent().parent().append(html);
}
});
}
else
{
// The textbox is on the page so check if its visible/showing
if (jQuery('#reply').is(':visible'))
{
// The textbox is visible so hide it
jQuery('#reply').hide();
}
else
{
// The textbox is hidden so show it
jQuery('#reply').show();
}
}
});
Редактировать : Я также изменил ваш var thiss = jQuery(this);
на var thiss = this;
this
- это уже объект jQuery, поэтому ему не нужно проходить через jQuery(this)
, чтобы превратить его в один.