javascript - 我似乎无法弄清楚我的 CSS 问题

标签 javascript html css

我似乎无法弄清楚这一点。我的网页在 http://rayku.com/start有一个文本框,当有人开始输入时,它会展开下面的表格:

expanded form http://snpr.cm/iurnmx.jpg

它的工作原理是,如果您在不输入任何内容的情况下从文本框中取消选择,它将返回到其原始状态。但是,它似乎工作得很好,如果我单击其下方表单本身上的任何内容,它就会返回到其原始状态。

如果我不在文本框中键入任何内容并且不单击其下方表单的任何位置,我如何更改它以便仅返回其原始状态?

谢谢!

最佳答案

您需要在允许“关闭”动画之前检查该字段的值。像这样:

//store object in var for efficiency
var mainQuestion = $('.main-question input');
var initialValue = mainQuestion.val();

mainQuestion.focus(function(){
    //blank out field on focus
    if(mainQuestion.val() == initialValue){
        mainQuestion.val('');
    }
    //animate opening here
});

mainQuestion.blur(function(){
    //check to see if user has typed anything in
    if((mainQuestion.val() == initialValue) || !mainQuestion.val().length ){
        //reset value
        mainQuestion.val(initialValue);
        //animate closing here
    }
});

关于javascript - 我似乎无法弄清楚我的 CSS 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9224170/

相关文章:

php - 如何获取没有html标签的文本

html - flask 出现没有导航栏按钮

html - 无法在 Safari 和 Chrome (WebKit) 中将 `margin` 添加到 `<legend>` 元素

html - 使用 Flexbox 在 DIV 元素之上创建网格

jquery - 如何为响应式标签添加背景

javascript - jQuery 使用路径参数验证远程选项

javascript - Angular Highchart-ng 安装

javascript - 在 jQuery 单击事件上重用 ajax 调用结果

javascript - JS - 对象到数组到 Google Sheets 批量更新

javascript将html标签添加到所有输入必填字段