2016-04-14 27 views
0

テキストボックスにローディングスピナーを追加するには、入力を開始して最大長に達すると、スピナーをロードする代わりに緑色のチェックマークが表示されます。テキストボックスにローディングスピナーを追加するにはどうすればいいですか?

私はイオンアプリでこれをやっています。

私は部分的に試しましたが、完了方法はわかりません。 jqueryが必要かもしれませんが、私はそれについて多くの知識を持っていません。ここで

が私のコードです:

<input id='inputsource' maxlength="10" /> 

はCSS:

.loadinggif { 
    background:url('img/ajax-loader.gif') no-repeat right center; 
} 
.greentick { 
    background:url('img/greentick.png') no-repeat right center; 
} 
+0

の可能性のある重複したこれらの線に沿って

#inputSourceIndicator { width: 16px; height: 16px; display: inline-block; } 

か何か含める必要があります(http [ボタンのクリックでテキストボックスに負荷スピナーを表示する方法を?]:// http://stackoverflow.com/questions/15774710/how-to-clicking-of-a-button) show-loading-image-animated-gif-file-inside-autocomplete-textbox- –

+0

を使用してくださいこれを確認してくださいhttp://stackoverflow.com/questions/15774710/how-to-show-loading-image-animated-gif-file- inside-autocomplete-textbox-using&http://stackoverflow.com/questions/12837335/how-to-display-loading-spinner-in-a-textbox-on-clicking-of-a-bu ttonあなたはhow-toのアイデアを得るでしょう –

答えて

1

たぶん、あなたは私があなたのイメージへのアクセス権を持っていない、この(sinnceを試みることができる、私はちょうど状態を示すために、境界線の色を使用しました):

$('#inputsource').on('keydown', function() { 
 
    $(this).addClass('loadinggif'); 
 
    }) 
 
    .on('blur', function() { 
 
    $(this).removeClass('loadinggif'); 
 
    }) 
 
    .on('keyup', function() { 
 
    var $this = $(this); 
 

 
    if ($this.val().length >= 10) { 
 
     $this 
 
     .removeClass('loadinggif') 
 
     .addClass('greentick'); 
 
    } else { 
 
     $this.removeClass('greentick'); 
 
    } 
 
    });
.loadinggif { 
 
    background: url('img/ajax-loader.gif') no-repeat right center; 
 
    border: 1px solid tomato; 
 
    outline: none; 
 
} 
 

 
.greentick { 
 
    background: url('img/greentick.png') no-repeat right center; 
 
    border: 1px solid yellowgreen; 
 
    outline: none; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<input id='inputsource' maxlength="10" />

あなたはまた、各キー押下に

<input id='inputSource'><div id='inputSourceIndicator' onkeyup='myFunc(this.value);></を呼び出すための機能を追加する必要があります

<input id='inputSource'><div id='inputSourceIndicator'></ div>の

としてあなたのhtmlが表示される場合がありますので、あなたが実際の入力に画像を追加することはできません
1

div>の

あなたのJS関数は次のようになり

function myFunc(value) { 
    // do check of whatever 
    // if check is false 
    // change the class of the indicator 
     document.getElementById('inputSourceIndicator').className = "loadinggif"; 
    // otherwise show the other class 
     document.getElementById('inputSourceIndicator').className = "greentick"; 

あなたのCSSも:-)

関連する問題