http://lab.synck.com/Cal3.0/
上記URLのカレンダーですが、日付にマウスポインタをあてるとテキストが日付の真下に表示されますよね。オンマウスの記述がキーなのだと思うのですが、
これを真下に表示ではなくてHTMLでテキストボックスを1行作って、作ったテキストボックスに表示させるようにするにはどのようにすればいいでしょうか。
または、真下表示ではなく、日付の1個したの段の1番左端からの表示でもかまいません。
まったくわからず困っています。。
No.4ベストアンサー
- 回答日時:
ちょっとだけ だそく(表示位置を変える)&難読化?
ぜんかくくうはくは、はんかくにしてください。
そ~してからの~ http://jsbeautifier.org/
<!DOCTYPE html>
<title></title>
<meta charset="utf-8">
<style>
table.calendar {
border : 1px gray solid;
background : #ffe;
}
table.calendar th,
table.calendar td {
border : 1px gray solid;
width : 4em;
text-align : center;
}
table.calendar th:nth-of-type(1) {
background : #fee;
color : red;
}
table.calendar td:nth-of-type(1)
{
background : #fee;
color : red;
}
table.calendar th:nth-of-type(7) {
background : #eef;
color : blue;
}
table.calendar td:nth-of-type(7)
{
background : #eef;
color : blue;
text-align : center;
}
table.calendar td > span {
display : none;
}
input#mess {
display : none;
position : absolute;
border : 3px green double;
}
</style>
<body>
<table class="calendar">
<tr>
<th>Sun <th>Mon <th>Tue <th>Wed <th>Thu <th>Fri <th>Sat
<tr>
<td>1<span>message1</span>
<td>2
<td>3
<td>4
<td>5<span>message5</span>
<td>6
<td>7<span>message7</span>
</table>
<input type="text" value="" id="mess">
<script>
var viewMessage = (function () {
var inp = document.getElementById ('mess');
var style = inp.style;
var memory = null;
return function (text, baseNode, side) {
var p, x, y;
if (baseNode) {
if (memory == baseNode) return;//TDの中にタグがあると… 無駄を省く
memory = baseNode;
p = getPosition (baseNode);
inp.value = text;
style.width = baseNode.offsetWidth + 'px';
switch (side) {
case 1 :
x = baseNode.offsetWidth; y = 0; break;
case 2 :
x = 0; y = -baseNode.offsetHeight; break;
case 3 :
x = -baseNode.offsetWidth; y = 0; break;
case 4 : default :
x = 0; y = baseNode.offsetHeight; break;
}
style.left = p.x + x + 'px';
style.top = p.y + y + 'px' ;
style.display = 'block';
}
else {
inp.style.display = 'none';
memory = null;
}
};
}) ();
//要素の位置をもとめる
function getPosition (e, x, y) {
for (x = y = 0; e; e = e.offsetParent)
x += e.offsetLeft, y += e.offsetTop;
return {x: x, y: y};
}
//親探し
function parentCheck (e, type, value) {
do if (e[type] == value) break; while (e = e.parentNode); return e;
}
//mouse over のイベントハンドラ
function handler (event) {
var tb, td, sp;
var e = event.target;
var cname = 'calendar';
if ((td = parentCheck (e, 'tagName', 'TD')))//親にTDがあり
if ((sp = td.querySelector ('span')))//その中にSPANがあり
if ((tb = parentCheck (td, 'tagName', 'TABLE')))//先祖にTABLEがあり
if (tb.classList.contains (cname))//それがcalendarならば
return viewMessage (sp.textContent, td.parentNode, 4);//表示
viewMessage ();
}
document.addEventListener ('mouseover', handler);
</script>
No.3
- 回答日時:
ieは、するぅ。
めずらしくこめんとつき。ぜんかくくうはくははんかくに。しょしんしゃように、かけたとおもう。すたいるがださいのは、かんべんね。
<!DOCTYPE html>
<title></title>
<meta charset="utf-8">
<style>
table.calendar {
border : 1px gray solid;
background : #ffe;
}
table.calendar th,
table.calendar td {
border : 1px gray solid;
width : 4em;
text-align : center;
}
table.calendar th:nth-of-type(1) {
background : #fee;
color : red;
}
table.calendar td:nth-of-type(1)
{
background : #fee;
color : red;
}
table.calendar th:nth-of-type(7) {
background : #eef;
color : blue;
}
table.calendar td:nth-of-type(7)
{
background : #eef;
color : blue;
text-align : center;
}
table.calendar td > span {
display : none;
}
input#mess {
display : none;
position : absolute;
border : 3px green double;
}
</style>
<body>
<table class="calendar">
<tr>
<th>Sun <th>Mon <th>Tue <th>Wed <th>Thu <th>Fri <th>Sat
<tr>
<td>1<span>message1</span>
<td>2
<td>3
<td>4
<td>5<span>message5</span>
<td>6
<td>7<span>message7</span>
</table>
<input type="text" value="" id="mess">
<script>
var viewMessage = (function () {
var inp = document.getElementById ('mess');
var style = inp.style;
var memory = null;
return function (text, baseNode) {
var p;
if (baseNode) {
if (memory == baseNode) return;//TDの中にタグがあると… 無駄を省く
memory = baseNode;
p = getPosition (baseNode);
inp.value = text;
style.width = baseNode.offsetWidth + 'px';
style.left = p.x + 'px';
style.top = p.y + baseNode.offsetHeight + 'px' ;
style.display = 'block';
}
else {
inp.style.display = 'none';
memory = null;
}
};
}) ();
//要素の位置をもとめる
function getPosition (e) {
var x, y; x = y = 0;
while (e) x += e.offsetLeft, y += e.offsetTop, e = e.offsetParent;
return {x: x, y: y};
}
//親探し
function parentCheck (e, type, value) {
do if (e[type] == value) break; while (e = e.parentNode);
return e;
}
//mouse over のイベントハンドラ
function handler (event) {
var tb, td, sp;
var e = event.target;
var cn = ' calendar ';
if ((td = parentCheck (e, 'tagName', 'TD')))//親にTDがあり
if ((sp = td.querySelector ('span')))//その中にSPANがあり
if ((tb = parentCheck (e, 'tagName', 'TABLE')))//先祖にTABLEがあり
if (0 <= (' '+ tb.className + ' ').indexOf (cn))//それがcalendarならば
return viewMessage (sp.textContent, td.parentNode);//表示
viewMessage ();
}
document.addEventListener ('mouseover', handler);
</script>
No.2
- 回答日時:
#1さんのを書くと以下。
<!DOCTYPE html>
<html lang="ja">
<head><meta charset="utf-8"><title></title>
<script>
document.addEventListener("DOMContentLoaded", function(){
//(2)spanのデータをinnerHTMLやnodeValueなどで抽出する
var text = document.getElementById('span').innerHTML;
//(3)document.getElementByIDでテキストボックスを指定して、valueを書き換える
document.getElementById('textbox').value = text;
}, false);
</script>
</head>
<body>
<p><span id="span">毎月1日は激安セールの日☆</span></p>
<!--(1)テキストボックスにidをふる-->
<p><input type="text" id="textbox" value=""></p>
</body></html>
(1)のテキストボックスをjsで生成する方法もありますが、今回はhtmlに直書きです。
addEventListener使ってるのでIEでは動きません。
実際にはクロスブラウザ対応の書き方をするか、jqueryなどのライブラリを使いましょう。
getElementByIdについては以下。
https://developer.mozilla.org/ja/docs/DOM/docume …
No.1
- 回答日時:
表示される文字はtd内にあるdisplay:noneされたspanのデータだというのはわかりますね?
であればその内容をテキストボックスに表示するのであれば
(1)テキストボックスにidをふる
(2)spanのデータをinnerHTMLやnodeValueなどで抽出する
(3)document.getElementByIDでテキストボックスを指定して、valueを書き換える
この回答への補足
ありがとうございます。
(3)の手法が勉強不足で、わかりません・・・javascript超初心者なので・・・
日付の1個したの段の1番左端からの表示をさせたほうが、手法としては簡単なのでしょうか?
そうだとしたらそのやりかたもご教示お願いできませんでしょうか・・・
お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!
関連するカテゴリからQ&Aを探す
おすすめ情報
- ・漫画をレンタルでお得に読める!
- ・人生のプチ美学を教えてください!!
- ・10秒目をつむったら…
- ・あなたの習慣について教えてください!!
- ・牛、豚、鶏、どれか一つ食べられなくなるとしたら?
- ・【大喜利】【投稿~9/18】 おとぎ話『桃太郎』の知られざるエピソード
- ・街中で見かけて「グッときた人」の思い出
- ・「一気に最後まで読んだ」本、教えて下さい!
- ・幼稚園時代「何組」でしたか?
- ・激凹みから立ち直る方法
- ・1つだけ過去を変えられるとしたら?
- ・【あるあるbot連動企画】あるあるbotに投稿したけど採用されなかったあるある募集
- ・【あるあるbot連動企画】フォロワー20万人のアカウントであなたのあるあるを披露してみませんか?
- ・映画のエンドロール観る派?観ない派?
- ・海外旅行から帰ってきたら、まず何を食べる?
- ・誕生日にもらった意外なもの
- ・天使と悪魔選手権
- ・ちょっと先の未来クイズ第2問
- ・【大喜利】【投稿~9/7】 ロボットの住む世界で流行ってる罰ゲームとは?
- ・推しミネラルウォーターはありますか?
- ・都道府県穴埋めゲーム
- ・この人頭いいなと思ったエピソード
- ・準・究極の選択
デイリーランキングこのカテゴリの人気デイリーQ&Aランキング
-
テーブルのセルのクリック時、...
-
selectのonChangeが動作しません
-
jquery にて、アラートダイアロ...
-
javascriptのカルーセル
-
Table内TDの子要素を移動させた...
-
<JavaScript>tableタグを入力不...
-
指定した箇所へスクロールさせたい
-
return trueとreturn falseの用...
-
特定<table>内の<td>の色を変える
-
value内に変数を入れたい
-
確認ダイアログの出し方(JavaS...
-
至急!GetElementById でtdの...
-
HTML中のTABLEのデータを抽出す...
-
ひ孫に当たるiframe から親ウイ...
-
XMLHttpRequestを利用してPHPへ...
-
innerHTML内では改行は禁止?
-
プルダウンで選択すると、DBの...
-
slickのレスポンシブ > center...
-
onchangeイベントを強制的に発...
-
全てのselect要素をデフォルト...
マンスリーランキングこのカテゴリの人気マンスリーQ&Aランキング
-
<JavaScript>tableタグを入力不...
-
テーブルの行数を可変長にした...
-
selectのonChangeが動作しません
-
画面表示とともに、テーブルの...
-
javascriptで<table>背景色の取得
-
javascriptでクリックするごと...
-
テキストエリアに入力した改行...
-
【jQuery】tableループ内のIDの...
-
<iframe>内にHTMLをランダム表...
-
javascriptで画像をテーブルに...
-
WEB制作に関する質問です。コン...
-
javascript でテーブル操作
-
カレンダーに印を付けたい
-
日にち指定によるテーブル/行の...
-
テーブルのtdの中に、重複避け...
-
innerHTMLでのテーブル作成
-
プルダウンメニューを表の中に...
-
簡単なJavaスロットマシーンに...
-
javascriptで表に画像を貼る
-
javascriptで画像の移動
おすすめ情報