<section />
jQuery UI ダイアログに詰め込むコンテンツを含む div で構成される非表示があります。document.ready では、これらの div をループ処理し、それぞれの div の ID を取得し、ダッシュをスペースに置き換え、各単語を大文字にして、それを title 変数に格納します。dialogs[]
次に、それを配列に入れるオブジェクト リテラルで使用します。シンプルですね。
HTML の簡素化されたバージョン:
<section id="dialog-content" class="hidden">
<div id="some-dialog">
// awesome dialog content here
</div>
<div id="another-dialog">
// awesome dialog content here
</div>
<div id="modal-dialog">
// awesome dialog content here
</div>
</section>
JavaScript の簡素化されたバージョン:
var dialogs = [],
$container = $("#dialog-content");
$content = $container.find("> div");
$content.each(function (i)
{
var $this = $(this),
id = $this.attr("id"),
title = id.replace(/\-/g, " ");
console.log(title);
dialogs[dialogs.length] =
{
trigger: $("#" + id + "-trigger"),
title: title,
content: $this.html()
};
});
ところで-カスタムプロパティを使用してdivに追加できることは知っています$.data()
が、マークアップをできるだけ最小限にしたかったので、この特定の可能性に興味があります。だから、それは私の例ではなく、目の前の問題です。
繰り返しますが、問題は次のとおりです。
text-transform: capitalize;
CSSと同じように、JavaScript を介して変数内の各単語を大文字にする方法を教えてください。