質問編集履歴
4
タグの修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -7,7 +7,7 @@
|
|
7
7
|
チェックボックスをチェックするとテキストボックスに値が入力されます。
|
8
8
|
その後にボタンをクリックすることで、モーダルウィンドウ内にあるテキストボックスに入力されている値をモーダルウィンドウ外のテキストボックスに移したいです。
|
9
9
|
|
10
|
-
```
|
10
|
+
```HTML
|
11
11
|
...
|
12
12
|
<input type="text" id="keyword" name="keyword" size="30" disabled="disabled"/>
|
13
13
|
<div id="select">
|
3
情報の追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -35,4 +35,124 @@
|
|
35
35
|
試しにJavaScript組んでみたのですが、うまくいかず...
|
36
36
|
どうかご教授お願いします。
|
37
37
|
|
38
|
+
モーダルウィンドウ自体は以下のように実装しています。
|
39
|
+
```HTML
|
40
|
+
<!-- ここからモーダルウィンドウ -->
|
41
|
+
<div id="modal-content">
|
42
|
+
<!-- モーダルウィンドウのコンテンツ開始 -->
|
38
|
-
|
43
|
+
<p>モーダルウィンドウのコンテンツをHTMLで自由に編集することができます。画像や、動画埋め込みなど、お好きなものを入れて下さい。</p>
|
44
|
+
<p>「閉じる」か「背景」をクリックするとモーダルウィンドウを終了します。</p>
|
45
|
+
<p><a id="modal-close" class="button-link">閉じる</a></p>
|
46
|
+
<!-- モーダルウィンドウのコンテンツ終了 -->
|
47
|
+
</div>
|
48
|
+
|
49
|
+
<p><a id="modal-open" class="button-link">クリックするとモーダルウィンドウを開きます。</a></p>
|
50
|
+
<!-- ここまでモーダルウィンドウ -->
|
51
|
+
```
|
52
|
+
|
53
|
+
|
54
|
+
```CSS
|
55
|
+
#modal-content{
|
56
|
+
width:50%;
|
57
|
+
margin:1.5em auto 0;
|
58
|
+
padding:10px 20px;
|
59
|
+
border:2px solid #aaa;
|
60
|
+
background:#fff;
|
61
|
+
z-index:2;
|
62
|
+
position:fixed;
|
63
|
+
display:none;
|
64
|
+
overflow: auto;
|
65
|
+
max-height: calc(100vh - 1.5em);
|
66
|
+
}
|
67
|
+
|
68
|
+
.button-link{
|
69
|
+
margin-left : 60px;
|
70
|
+
text-align:center;
|
71
|
+
-moz-border-radius: 5px;
|
72
|
+
-webkit-border-radius: 5px;
|
73
|
+
border-radius: 5px;
|
74
|
+
}
|
75
|
+
|
76
|
+
.button-link:hover{
|
77
|
+
cursor:pointer;
|
78
|
+
color:#f00;
|
79
|
+
}
|
80
|
+
|
81
|
+
#modal-overlay{
|
82
|
+
z-index:1;
|
83
|
+
display:none;
|
84
|
+
position:fixed;
|
85
|
+
top:0;
|
86
|
+
left:0;
|
87
|
+
width:100%;
|
88
|
+
height:120%;
|
89
|
+
background-color:rgba(0,0,0,0.75);
|
90
|
+
overflow: auto;
|
91
|
+
}
|
92
|
+
|
93
|
+
```
|
94
|
+
|
95
|
+
```JavaScript
|
96
|
+
<!-- モーダルウィンドウ実装用 -->
|
97
|
+
<script>
|
98
|
+
jQuery(function($){
|
99
|
+
|
100
|
+
//モーダルウィンドウを出現させるクリックイベント
|
101
|
+
$("#modal-open").click( function(){
|
102
|
+
|
103
|
+
//キーボード操作などにより、オーバーレイが多重起動するのを防止する
|
104
|
+
$( this ).blur() ; //ボタンからフォーカスを外す
|
105
|
+
if( $( "#modal-overlay" )[0] ) return false ; //新しくモーダルウィンドウを起動しない (防止策1)
|
106
|
+
//if($("#modal-overlay")[0]) $("#modal-overlay").remove() ; //現在のモーダルウィンドウを削除して新しく起動する (防止策2)
|
107
|
+
|
108
|
+
//オーバーレイを出現させる
|
109
|
+
$( "body" ).append( '<div id="modal-overlay"></div>' ) ;
|
110
|
+
$( "#modal-overlay" ).fadeIn( "slow" ) ;
|
111
|
+
|
112
|
+
//コンテンツをセンタリングする
|
113
|
+
centeringModalSyncer() ;
|
114
|
+
|
115
|
+
//コンテンツをフェードインする
|
116
|
+
$( "#modal-content" ).fadeIn( "slow" ) ;
|
117
|
+
|
118
|
+
//[#modal-overlay]、または[#modal-close]をクリックしたら…
|
119
|
+
$( "#modal-overlay,#modal-close" ).unbind().click( function(){
|
120
|
+
|
121
|
+
//[#modal-content]と[#modal-overlay]をフェードアウトした後に…
|
122
|
+
$( "#modal-content,#modal-overlay" ).fadeOut( "slow" , function(){
|
123
|
+
|
124
|
+
//[#modal-overlay]を削除する
|
125
|
+
$('#modal-overlay').remove() ;
|
126
|
+
|
127
|
+
} ) ;
|
128
|
+
|
129
|
+
} ) ;
|
130
|
+
|
131
|
+
} ) ;
|
132
|
+
|
133
|
+
//リサイズされたら、センタリングをする関数[centeringModalSyncer()]を実行する
|
134
|
+
$( window ).resize( centeringModalSyncer ) ;
|
135
|
+
|
136
|
+
//センタリングを実行する関数
|
137
|
+
function centeringModalSyncer() {
|
138
|
+
|
139
|
+
//画面(ウィンドウ)の幅、高さを取得
|
140
|
+
var w = $( window ).width() ;
|
141
|
+
var h = $( window ).height() ;
|
142
|
+
|
143
|
+
// コンテンツ(#modal-content)の幅、高さを取得
|
144
|
+
// jQueryのバージョンによっては、引数[{margin:true}]を指定した時、不具合を起こします。
|
145
|
+
// var cw = $( "#modal-content" ).outerWidth( {margin:true} );
|
146
|
+
// var ch = $( "#modal-content" ).outerHeight( {margin:true} );
|
147
|
+
var cw = $( "#modal-content" ).outerWidth();
|
148
|
+
var ch = $( "#modal-content" ).outerHeight();
|
149
|
+
|
150
|
+
//センタリングを実行する
|
151
|
+
$( "#modal-content" ).css( {"left": ((w - cw)/2) + "px","top": ((h - ch)/2) + "px"} ) ;
|
152
|
+
|
153
|
+
}
|
154
|
+
|
155
|
+
} ) ;
|
156
|
+
|
157
|
+
</script>
|
158
|
+
```
|
2
処理結果について追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -33,4 +33,6 @@
|
|
33
33
|
```
|
34
34
|
|
35
35
|
試しにJavaScript組んでみたのですが、うまくいかず...
|
36
|
-
どうかご教授お願いします。
|
36
|
+
どうかご教授お願いします。
|
37
|
+
|
38
|
+
ちなみに上の実装で動かすと、チェックボックスの値がモーダルウィンドウ内のテキストボックスに入力されるとこまではうまく動くのですが、OKボタンをクリックしても特に何も起きない...といった状態です。
|
1
書式の修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -25,9 +25,9 @@
|
|
25
25
|
|
26
26
|
```JavaScript
|
27
27
|
function OK() {
|
28
|
-
('$ok').click
|
28
|
+
('$ok').click = function OK() {
|
29
29
|
var search_material = document.getElementById('keyword');
|
30
|
-
('$front_searchfield').value = search_material;
|
30
|
+
('$front_searchfield').value == search_material;
|
31
31
|
}
|
32
32
|
}
|
33
33
|
```
|