const animals = ["pigs", "goats", "sheep"]; const count = animals.push("cows"); console.log(count); // Expected output: 4 console.log(animals); // Expected output: Array ["pigs", "goats", "sheep", "cows"] animals.push("chickens", "cats", "dogs"); console.log(animals); // Expected output: Array ["pigs", "goats", "sheep", "cows", "chickens", "cats", "dogs"]
HTML5のCanvasとJavaScriptの勉強としてアナログ時計を作ってみました。このまとめは、それに関するつぶやき群です。 完成したアナログ時計 http://senritsuki.com/program/clock/ 続きを読む
W3Schools offers a wide range of services and products for beginners and professionals, helping millions of people everyday to learn and master new skills. Free Tutorials Enjoy our free tutorials like millions of other internet users since 1999
I have one text input and one button (see below). How can I use JavaScript to trigger the button's click event when the Enter key is pressed inside the text box? There is already a different submit button on my current page, so I can't simply make the button a submit button. And, I only want the Enter key to click this specific button if it is pressed from within this one text box, nothing else. <
十二章第三回 History APIこのページの最終更新日:2018年7月29日 次に紹介するのがHTML5 History APIです。Historyとは履歴のことです。履歴関係のことは、historyという名前のオブジェクトから利用可能です。 古典的な履歴操作実はこのhistory自体は昔からあって、いくつかメソッドを持っていました。 history.back(); 例えばhistory.backメソッドは、いわゆるブラウザの「戻る」ボタンと同じ動きです。 実際にやってみましょう。 このボタンは次のようにできています。 <input type="button" value="戻る" onclick="history.back()"> このボタンを押すと、ブラウザの「戻る」ボタンを押したときと同じように前のページに戻ります。 逆に「進む」はhistory.forward()です。他に、「
文字列操作の比較表: Ruby, Python, JavaScript, Perl, C++ Ruby, Python, JavaScript, Perl, C++ の文字列操作の比較表を作りました。配列操作の比較表の続編です。間違いなどがあったらご指摘いただけると助かります。 Ruby (String) Python (str) JavaScript (String) Perl C++ (std::string)
例えば、『123456789』という数値を、『123,456,789』という文字列にしたい場合、よく取られる手法としては、下記のような正規表現やループを使う方法があります。例えば下記のような感じ(参考:JavaScriptで数値を桁区切り (カンマ区切り) にする方法)。 var num = 123456789; String( num ).replace( /(\d)(?=(\d\d\d)+(?!\d))/g, '$1,' ); //=> "123,456,789" // 余談だけど、数値を文字列に変換する際はこんな書き方もできる num.toString().replace( /(\d)(?=(\d\d\d)+(?!\d))/g, '$1,' ); //=> "123,456,789" (num+"").replace( /(\d)(?=(\d\d\d)+(?!\d))/g, '$1,
正規表現リファレンス(CoffeeScript) 正規表現はパターンとフラグを/で区切って記述します。フラグは指定しなくても構いません。 /パターン/フラグ フラグ フラグには以下の文字が指定可能です。 g 最初の1個だけでなく、文字列の最後まで検索を繰り返します。「グローバルマッチ」とも呼ばれます。 文字列.replaceメソッドでgフラグを指定すると、見つかったすべての部分文字列が置換されます。 # 最初のaaだけが置換される "aabbaabb".replace(/aa/, "cc") # => 'ccbbaabb' # すべてのaaが置換される "aabbaabb".replace(/aa/g, "cc") # => 'ccbbccbb' i 大文字小文字を区別せずにマッチします。 # 大文字のXYZにのみマッチする /XYZ/.test("xyz") # => false # 大
replace() で同じ要素内で複数組のテキストを置換 同じ要素内で複数のテキストを変換したい場合のサンプルです。 <script src="./jquery.min.js"></script> <script> $(document).ready(function(){ $('.replace').each(function(){ var txt = $(this).html(); $(this).html(txt .replace(/A/g,'B') .replace(/C/g,'D') .replace(/E/g,'F') ); }); }); </script> 出力結果ですが、元のテキストはこちら。
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く