Javascript
 Computer >> コンピューター >  >> プログラミング >> Javascript

AngularJSとHTML5を使用してリスト内のテキスト入力にフォーカスを設定する方法


リストに入力されたテキストにフォーカスを設定するには、次のコードを試してください。

newApp.directive('focus', function () {
   return function (scope, element, attrs) {
      attrs.$observe('focus', function (newValue) {
         newValue === 'true' && element[0].focus();
      });
   }
});

HTMLは次のとおりです。

<input type="text" ng-model="cues[$index].text" focus="{{cue.isNewest}}"
class="input-xlarge" />{{cue.isNewest}}

  1. JavaScriptで<strong>タグにテキストを設定するにはどうすればよいですか?

    まず、要素-を設定します <strong id="strongDemo">Replace This strong tag</strong> 上記で設定されたid属性は、#-を使用してテキストを設定するために使用されます。 $(document).ready(function(){    $("#strongDemo").html("Actual value of 5+10 is 15....."); }); 例 <!DOCTYPE html> <html lang=&qu

  2. CSSでフォーカスの入力フィールドをクリアするにはどうすればよいですか?

    以下は、フォーカスのある入力フィールドをクリアするためのコードです- 例 <!DOCTYPE html> <html> <head> <h1>Clearing an input field on focus example</h1> <input type="text" onfocus="this.value=''" value="Some random text..."> <h2>Click on the above field to