0

当文本框控件为空时,我需要fadeOut在文本框控件旁边显示 5 秒钟的消息。请告诉我如何实现这一目标。

<?php
echo "<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js'></script>";
echo "<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.cycle.all.js'></script>";
include_once('db_con.php');
$error = array("txt_categoryErr" => "","txt_brandErr" => "");
echo "<script>
$(document).ready(function(){
$('#sub').click(function(){ $('#toFade').delay(1000).fadeOut(3000); });
</script>

if(isset($_POST['submit'])){
$catq = $_POST['txtName'];
if($catq!=''){
$query = "INSERT INTO `categories`(`id`, `parent_id`, `name`) VALUES ('','','$catq')";
}else{
$error["txt_categoryErr"]="Please enter a valid category name";
}    

?>

<div class="txtCategory">
Category Name: <input type="text" id="txt_name" name="txtName" size="12" maxlength="20">
<input type="submit" class="btnsub" id="sub" name="submit" value="Add">
<div id="toFade"><small name="Errtxt" class="errorText"><?php echo $error['txt_categoryErr']; ?></small></div>
</div>
4

1 回答 1

0

我认为这是关于 javascript/css

将 style dispaly:none 设置为 #toFade 并尝试

$('#sub').click(function(){ 
    if ( $('#txt_name').val() == '' ) {            
        $('#toFade').show().delay(5000).fadeOut(600);
    }
});
于 2013-09-12T07:50:28.747 回答