JavaScriptの文字列置換とjQueryのDOM要素置換について、まとめて紹介します。 特にJavaScriptの文字列置換はいつもやり方を忘れてしまうので、このエントリーに保存しておきます。 1.replace()による文字列置換 基本的な文字列置換は、JavaScriptのreplace()メソッドを利用します。 var text = "foofoo"; var result = text.replace('foo', 'bar'); 実行結果(resultの内容) barfoo 2.replace()の正規表現による置換 replace()メソッドの第1パラメータに正規表現を指定すれば、さらに強力な文字列置換が行えます。 var text = "foofoo"; var result = text.replace(/foo/g, 'bar'); 実行結果(resultの内容)
本日行われた Shibuya.js の発表資料をアップしました。 さいきんの JavaScript テスト / Test.js - Shibuya.js 発表資料 View more presentations from hotchpotch JS のテスティングフレームワークのおおざっぱな説明や JavaScript テストにおける問題、それについての解決方法の一つ、CUI でのテスト、Envjs、エンドツーエンドテストにおける JS / Ajax のテスト、終わりにちらっと Phantomjs の話があります。 スライドの最後にあるように、やはりまだコレだ!という JS のテスティングフレームワークは存在しなく、今後 JS のテストは『僕らが書きたいテスト』をどれだけ簡単に書ける・書く手法が確立されるかによって流行廃りは決まってくるんじゃないかなぁ、と思ってます。そのうちの一つがスライ
「エレメントの属性を削除」サンプルコード <html> <head> <title>element.removeAttribute - エレメントの属性を削除</title> </head> <body> <!--エレメントの属性を削除のサンプル--> <a id="sample" rel="test">samplelink</a><br> <script type="text/javascript"> function findElement() { var element = document.getElementById("sample"); element.removeAttribute("rel"); alert("aタグのrel属性は「"+element.getAttribute("rel")+"」です"); } </script> <button onclick="findE
この機能を実行するにはprototype.jsが必要です 構文 Element.addClassName(element, className) 引数: element=エレメント, className=追加するクラス名 「エレメントにクラス名を追加する」サンプルコード <html> <head> <title>Element.addClassName - エレメントにクラス名を追加する</title> </head> <!--エレメントにクラス名を追加するのサンプル--> <script type="text/javascript" src="/js/prototype.js"></script> <script type="text/javascript"> function execute() { var item = $('sample'); if (!Element.hasCla
getElementByIdとgetElementsByNameってよく使い方を間違えます。(私だけかもですが。) ということで、基本中の基本のgetElementByIdとgetElementsByNameの使い方をまとめてみます。 ※「getElementByName」では無く「getElementsByName」だってところがちょっと重要です。 getElementByIdの基本的な使い方 getElementByIdの基本的な使い方は以下の通りです。 ◆ document.getElementById(id) (D1/e5/N6/O6) id 属性で指定した名前で要素を参照します。 oElement = document.getElementById("id1"); とほほのJavaScriptリファレンス - ドキュメントオブジェクトモデル(DOM) 「id 属性で指定した名前で
当サイトではCookieを使用しています。引き続き当サイトを閲覧することにより、ポリシーを受け入れたものとみなされます。今後表示しない詳しく見る
サービス終了のお知らせ NAVERまとめは2020年9月30日をもちましてサービス終了いたしました。 約11年間、NAVERまとめをご利用・ご愛顧いただき誠にありがとうございました。
企業システムのクライアントを開発するのに使う技術が変われば、IT部門に求められるスキルも変わる。最も大きな課題は、JavaScriptを使いこなすことだろう。これまで企業システムでは主役とはいえない開発言語だったが、今後は重要度が高まる。 JavaScriptを熟知することが必要 HTML5では、アプリケーションを制御するクライアント側のロジックは、JavaScriptで記述することになる。「本格的にHTML5ベースの情報システムを開発する企業には、HTML5とJavaScriptの両方を熟知した技術者が必要だ」と、NTTコミュニケーションズの小松氏はみる。 インターネットで入手できるHTML5用のオープンソースライブラリーもJavaScriptファイルが多い。例えばグラフを描画する「gRaphaël」や「Highcharts」などがある(図6)。これらは無料で利用でき、簡単なカスタマイズ
1.1 初期のJavaScript JavaScriptが強力で動的なオブジェクト指向言語である これって議論が分かれるところだけど書籍ではオブジェクト指向言語と言い切っている。 1.2 アプリケーションの構造化 大規模なjavaScriptアプリケーションを作成する上で鍵になるのは、「javaScriptの」アプリケーションをつくろうとはしないことです。まず、独立性の高いコンポーネントへとアプリケーションを分割するべきです。 粒度が細かいほうが制作しやすいし管理もしやすいと。 1.3 MVCとは MVCはデザインパターンの1つであり、アプリケーションをデータ(Model)とプレゼンテーションレイヤ(View)そしてユーザーインタラクションレイヤ(Controller)の3つに分割するという概念です。 大抵のWEBアプリケーションはこう分割できるよねと。 ユーザーがアプリケーションを操作し
【ゆっくり茶番劇 】 男から女の子になった 第百七話「元男の子は相談する」#ゆっくりロア #男から女の子になった #ゆっくり
業界初のHTML5モバイルアプリ用フレームワーク Sencha Touchを使えばタッチスクリーンを装備したApple iOSや Android端末上でネイティブアプリのようなWebアプリが開発可能です。 Web標準技術に準拠 Sencha TouchはHTML5、CSS3、JavaScriptに特化した世界初のアプリケーションフレームワークです。SSencha Touchはこれらの技術が持つ力を最大限に引き出し、かつ柔軟で最適化されたアプリケーション開発を可能にします。Sencha Touchでは、音声や動画を組み込む為のコンポーネントやデータをオフラインでも利用可能にするlocalStorageプロキシーなどでHTML5の機能が利用されています。またSencha TouchのスタイルシートではCSS3を最大限活用してとても堅牢なスタイリングレイヤーを実現しています。 このライブラリはそ
公開: 2012年7月14日17時5分頃 社内でJavaScriptの勉強会をやりたいという話が出てきたので、テキストをいろいろ検討。要件としてはこんな感じです。 週一で開催する予定参加者には営業やプロジェクトマネージャーなど、技術的な知識があまりない人も含まれる以前にHead First JavaScript (www.amazon.co.jp)を使って勉強会をやったことがあるらしいが、「バタ臭い」という評判だったらしいテキストの候補として挙げられたのは以下の4冊。 マンガでわかるJavaScript (www.amazon.co.jp)よくわかるJavaScriptの教科書 (www.amazon.co.jp)10日でおぼえるJavaScript入門教室 (www.amazon.co.jp)Head First JavaScript (www.amazon.co.jp)それぞれを見て評
シンプルで良さそうだったので一応備忘録。 Media Queriesライクにブレークポイントに 応じてスタイルを変更できるライブラリです。 非依存型で1KBと、超軽量スクリプトなので 簡単なキャンペーンサイトとかならこれでも いいかもしれないですね。 Media Queriesのようにデバイスを限定しないクロスブラウザ対応で、他のライブラリに依存せず利用出来る、圧縮版は1KBと軽量、というのが特徴です。 サイズに応じてスタイルが変わっています。何してるかというと、非常にシンプルで指定したブレークポイントに合わせて<html>にclassを付加させてるんですね。 サンプルどうぞ。 Sample ※動作確認はresponsivepxが便利です iPhoneだってOK。実機でも確認済みです。 コード <script src="syze.min.js"></script> <script>syze
これはかなり便利そうだったので備忘録。 ディスプレイサイズに応じて指定した要素 にclass名を加え、そのclassを使ってデザ インする事でレスポンシブなWebデザイン を設計出来るようにする為のライブラリ。 かなり便利そうです。 この発想はちょっと素敵でした。指定したサイズに応じて要素にclassを与えるので、Media Queryを使用したPCとスマフォ向けサイトで見た目をまったく別のものにすることも出来そう。 特にjQueryやmootoolsといったスクリプトに依存してないのもいいですね。イメージ的には部分的にMedia Queryを手軽に使える、という感じでした。 わずか5KBほどの非依存型軽量ライブラリです。ディスプレイサイズ等で要素が指定した数値になると、class名を与えてくれるので、環境によってデザインを簡単に変更できるようになります。 上記はMedia Query T
結構良さそうだったので備忘録。レスポンシブWebデザイン向けのライブラリです。モバイルのサイズになるとグローバルナビを横スライド式に切り替える、というもの。面白いですねー。 これ結構いいんじゃないでしょうか。レスポンシブWebデザインにするとどうしてもナビゲーションが縦長になりがちなのでその不満は解消できるアイデアですね。 PathやFacebookのiPhoneアプリのような横スライドメニューは使いやすいかもしれない。 Pathのようにというか、全く同じじゃないんですが、モバイルサイズになると横スライド式のメニューに変更するjQueryプラグインです。 ちょっといいアイデアですね。プラグインも圧縮版は3KBと軽量です。 タップすると左からメニューがスライドします。 手抜きで申し訳ないんですがサンプルです。 Sample※表示確認はresponsivepxを使うと楽です 実機で重いのは僕が
ちょっと気になってたjQueryプラグイン だったのでテストしてみました。表示 しているサイズに応じてレイアウトや フォントサイズを最適なものにしてく れる、というもの。Media Queryは使用 していないのでcssも綺麗に保てます。 場合によっては軽量化に繋がるかも、と思ったのでちょっとテストしてみたかったライブラリ。説明されてもあんまりピンとこないライブラリですけどwなんというか、かゆいところに手が届く的なやつです。 このようにサイズを表示変えるとフォントサイズやdivの幅も指示通り変わってくれます。Media Query択一だと、どうしても面倒になってくることもあるので、こういうスクリプトも覚えておくと保険になるかもですね。スクリプトはたったの6KBですので軽量化にも役に立つかもしれません。 尚、IE6と7には対応していません。 日本語でも問題ありませんでした。以下サンプルどうぞ
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く