をいくつかの詳細を持って[OK]を
)正規表現が参考になります(ページ全体または選出された要素をscaning、datatimeパターンを探し、それを再フォーマットし、ページに戻りますこれは:
例:http://jsfiddle.net/c5bHx/
<!DOCTYPE html>
<html>
<head><title>title</title></head>
<body>
<!-- your content -->
<!-- place this just inside your closing </body> tag -->
<script type="text/javascript>
var days = 'sunday,monday,tuesday,wednesday,thursday,friday,saturday'.split(',');
document.getElementById(days[(new Date()).getDay()]).className = 'bold';
</script>
</body>
</html>
CSS
.bold {
font-weight:bold;
}
EDIT:
ここで何が起こっているかの内訳です。私はそれをはるかに冗長にし、コードをさまざまな変数に展開して見やすくします。
// This simply creates a string of days in the week
var days = 'sunday,monday,tuesday,wednesday,thursday,friday,saturday';
// This splits the string on the commas, turning it into an Array of weekdays
days = days.split(',');
// Create a new Date object, representing today's date and time
var date = new Date();
// Get the number of the day of the week. 0 if sunday, 1 if monday, etc...
var dayNumber = date.getDay();
// Using the "dayNumber", get the day string by its index from the "days" array
var dayString = days[ dayNumber ];
// Select the element on the page that has the ID that matches the "dayString"
var dayElement = document.getElementById(dayString);
// Set the "class" property of the "dayElement" to the "bold" class.
dayElement.className = "bold";
日の文字列を配列に変換する必要はありません。入力するのに少し短く素早く。
あなたは行うことができます:
var days = ['sunday','monday','tuesday','wednesday','thursday','friday','saturday'];
これは、配列を作成しますので、あなたは.split()
を行う必要がありません。
詳細を記入してください。何ページ?ページのコードを投稿してください – Jason
あなたはもっと詳しく説明しなければなりません。 「月曜日」、「火曜日」などの単語をテキストの文字列で太字にしますか? –
申し訳ありませんが、iveさんが私に尋ねる気にならない場合は –