jquery中的Keyup功能缺陷

时间:2015-06-18 05:40:48

标签: javascript jquery ajax

我已使用 keyup() textbox 的值传递给 ajax 。但在清空文本框时,它会显示相关表中的所有内容。文本框为空时我想要一个空页面。任何人都可以帮我解决这个问题。代码是:

$('.form-control').keyup(function () {
    var name = $('#member_search').val();
    var phone = $('#member_contact').val();
    var father = $('#member_father').val();
    $.ajax({
        type: "post",
        url: "search_result.php",
        data: {
            name: name,
            contact: phone,
            father: father
        },
        success: function (data) {
            $('#result').html(data);
        }
    });
});

1 个答案:

答案 0 :(得分:0)

只需检查是否有任何内容已清空结果框

.testimonials { background-color: #e7d6e9; padding: 30px 0;}
.container { width: 90%; margin-left: auto; margin-right: auto; background-color: #e9e9e9;}
.quotename {  margin: 20px 0; position: relative; /*overflow: hidden; height: auto;*/}
a.tooltip {outline:none;}
a.tooltip h2 { text-decoration: none; border-bottom: 2px solid #00acb6; font-family: 'Montserrat', sans-serif; font-weight: 700; font-size: 20px; color: #00acb6; float: right; width: auto; margin: 0;}
a.tooltip strong {line-height:30px;}
a.tooltip:hover {text-decoration:none;} 
a.tooltip span {
    display:none; 
    padding:14px 20px;
    margin-top:-120px; 
    margin-right: -8px;
    width:150px; 
    line-height:16px;
    background: #e9e9e9;
    height: 70px;
    position: relative;
    float: right;
}
a.tooltip span h3 { margin:0;}
a.tooltip span:after, a.tooltip span:before {
    top: 100%;
    left: 75%;
    border: 3px solid transparent;
    content: " ";
    height: 0;
    width: 0;
    position: absolute;
    pointer-events: none;
}
a.tooltip span:after {
    border-color: rgba(0, 172, 182, 0);
    border-top-color: #e9e9e9;
    border-width: 10px;
    margin-left: -10px;
}
a.tooltip span:before {
    border-color: rgba(0, 172, 182, 0);
    border-top-color: #00acb6;
    border-width: 14px;
    margin-left: -14px;
}
a.tooltip:hover span{
    display:inline; position:relative; color:#111;
    border: 3px solid #00acb6; background: #e9e9e9; border-radius: 6px;}
a.tooltip span
{
    border-radius: 6px;
    border: 3px solid #00acb6;
}