简体   繁体   English

在模糊时更新引导进度栏

[英]Update bootstrap progress bar on blur

I cannot figure out why my javascript doesn't work. 我无法弄清楚为什么我的JavaScript无法正常工作。

  //Update Progress Bar
$('#photoUpload-name').blur(function () {
    var validName = $('#photoUpload-name').val();
    if (validName > 1) {
        $(function () {
            $(".progress-bar").css("width", "50%");
        });
    }
});

I know my project is set up correctly because $(".progress-bar").css("width", "50%"); 我知道我的项目设置正确,因为$(“。progress-bar”)。css(“ width”,“ 50%”); works outside the function. 在功能之外工作。

After the user, in this case, fills out their name and the input loses focus, I want it to check that there was at least 2 characters entered (validName > 1) then if there is, to update the progress bar. 在这种情况下,在用户填写了他们的姓名并且输入失去焦点之后,我希望它检查是否至少输入了2个字符(validName> 1),然后如果有,请更新进度条。

I've tried different variations of this, using focusout and it still doesn't work. 我已经尝试过使用焦距的不同变体,但仍然无法正常工作。

To check lenght you need: 要检查lenght您需要:

$('#photoUpload-name').val().length;

Because $('#photoUpload-name').val() just get the value. 因为$('#photoUpload-name').val()取值。

DEMO 演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM