這是我的代碼。即時通訊有問題,當我提交評論textarea將失去其位置。我不知道爲什麼。我檢查了它的CSS。沒有運氣。jquery/ajax問題顯示
$(document).ready(function(){
$("#box-table-a").tablesorter();
var messageArea = $('textarea#message');
var nameArea=$('#comment-name');
var submit=$('#submit-comment');
nameArea.val('Enter your name').css('color', '#666666');
messageArea.val('Leave your message here').css('color', '#666666');
messageArea.focus(function(){
$(this).val('').css('color', '#000000');
$(this).unbind('click').click(function(){
return false;
});
});
nameArea.focus(function(){
$(this).val('').css('color', '#000000');
$(this).unbind('click').click(function(){
return false;
});
});
$('input#submit-comment').click(function(){
// Store vars
var message = messageArea.hide().val();
var cname = nameArea.hide().val();
// Validation
if(message.length < 1 || message == "Leave your message here"){
submit.fadeOut('fast');
messageArea.fadeOut('slow', function(){
nameArea.fadeOut('slow');
var errorMessage = 'Oops! You haven’t typed anything. Please have another go...';
var error = $('<div id="too-short"><span class="error">' + errorMessage + '</span></div>').insertBefore($(this));
error.hide().fadeIn('slow', function(){
setTimeout(function(){
error.hide();
messageArea.fadeIn('slow');
nameArea.fadeIn('slow');
submit.fadeIn('slow');
}, 1000);
});
});
return false;
}
var dataString = 'message='+ message+'name='+ cname;
// Show loader
var loader = $('<div id="loader"><img class="load-gif" src="' + loaderImage.src + '" /></div>').insertBefore($(this));
//alert (dataString);
$.ajax({
type: "POST",
url: "commentconnect.php",
data: {message:message, name:cname},
success: function(data) {
$('div#loader').find('img.load-gif').remove();
$('div#loader').hide().fadeIn('slow');
$('span.limit').remove();
$('div#append').prepend(data);
$('input#submit-comment').unbind('click').click(function(){
return false;
});
}
});
return false;
});
});
//ive added the appended part of the comment which is in the table
<table align="left" style="margin-left:30px; width:520px; border:1px solid;">
<?php
while($fetchcom=mysql_fetch_array($comment))
{
echo"<tr>";
echo"<td style='font-size:15px'>";
echo $fetchcom['c_name'];
echo"</td>";
echo"<td align='right' style='font-size:12px; font-style:italic'>";
echo $fetchcom['date'];
echo"</td>";
echo"</tr>";
echo"<tr>";
echo"<td colspan='2' style='padding:10px 10px 5px 10px; font-size:14px; color:gray; font-style:italic;'>";
echo $fetchcom['Comment'];
echo"</td>";
echo"</tr>";
}
?>
<div id='append' style="margin-left:-20px; position:relative; width:300px;"></div>
</table>
<div id="submission">
<form name="comment-submission">
<div style="position:relative; float:left; left:30px; top:5px;" >Add Comment</div>
<div style="position:relative; left:30px; top:3px;"><input type="text" id="comment-name" /></div>
<textarea id="message" name="message" ></textarea>
<div style="position:relative; top:-85px; height:70px; width:100px; right:-458px;"><input type="button" id="submit-comment" value="Submit" /> </div>
</form>
<div class="clear"></div>
</div>
//和繼承人的CSS希望這有助於
div#submission {
position:relative;
height:50px;
width:520px;
}
div#submission textarea#message {
float:left;
width:400px;
height:46px;
padding:5px 25px 5px 5px;
border:1px solid #666;
font-family: Tahoma, sans-serif;
font-size:14px;
margin-left:30px;
}
#comment-name{
float:left;
width:400px;
height:20x;
padding:5px 25px 5px 5px;
border:1px solid #666;
font-family: Tahoma, sans-serif;
font-size:14px;
margin-bottom:5px;
}
div#submission input#submit-comment{
cursor:pointer;
height:30px;
width:70px;
margin-top:54px;
margin-left:5px;
color:#050;
font: bold 84% 'trebuchet ms',helvetica,sans-serif;
background-color:#fed;
border: 1px solid;
border-color: #696 #363 #363 #696;
filter:progid:DXImageTransform.Microsoft.Gradient
(GradientType=0,StartColorStr='#ffffffff',EndColorStr='#ffeeddaa');
}
我認爲這個問題是在預定(數據)的一部分。必須有東西在那裏添加恢復textarea的位置,但我不知道什麼和如何。即時通訊新的jQuery和ajax。
順便說一句我有截圖向你展示textarea提到。提交評論後http://i.stack.imgur.com/67eVU.png和繼承人截圖 - - 提交評論之前http://i.stack.imgur.com/zFSXC.png 由於事先
請注意,如果您使用的是jQuery選擇器的ID,請不要使用該元素。將`$('textarea#message')`更改爲`$('#message')`。第一種方法是多餘的,爲jQuery的選擇器引擎做了更多的工作。 – Stephen 2011-02-22 19:41:10
通過其新的(浮動)位置,我假定你是正確的,它在前置,但是,在你的代碼中缺少文本框的上下文。 它位於`div#append`嗎?如果是這樣,請添加完整的HTML上下文和與其相關的完整CSS。 – yossi 2011-02-22 19:54:35
我修改了上面的代碼,並添加了CSS和ID附加div – user628961 2011-02-23 13:37:19