モーダルウィンドウ内に以下を配置しています。
・テキストボックス(入力不可)
・複数のチェックボックス
・ボタン
チェックボックスをチェックするとテキストボックスに値が入力されます。
その後にボタンをクリックすることで、モーダルウィンドウ内にあるテキストボックスに入力されている値をモーダルウィンドウ外のテキストボックスに移したいです。
HTML
1... 2<input type="text" id="keyword" name="keyword" size="30" disabled="disabled"/> 3<div id="select"> 4 <input type="checkbox" name="check" id="prop" value="テスト1"> テスト1</input><br> 5 <input type="checkbox" name="check" id="prop" value="テスト2"> テスト2</input><br> 6 <button type="button" id="ok" name="ok" value="ok">OK</button> 7</div> 8 9<div id = "search"> 10 <input id="front_searchfield" type="text" maxlength="30" placeholder="例) テスト1 テスト2" name="s" class="front_searchfield" value="" style="color: black; border-color:#009245;"/> 11</div>
div id=selectのボタンをクリックすることで、div id=search内のfront_searchfieldのテキストボックスに入ってる値がinput id=keywordのテキストボックスに移るイメージです。
JavaScript
1function OK() { 2 ('$ok').click = function OK() { 3 var search_material = document.getElementById('keyword'); 4 ('$front_searchfield').value == search_material; 5 } 6}
試しにJavaScript組んでみたのですが、うまくいかず...
どうかご教授お願いします。
モーダルウィンドウ自体は以下のように実装しています。
HTML
1<!-- ここからモーダルウィンドウ --> 2<div id="modal-content"> 3 <!-- モーダルウィンドウのコンテンツ開始 --> 4 <p>モーダルウィンドウのコンテンツをHTMLで自由に編集することができます。画像や、動画埋め込みなど、お好きなものを入れて下さい。</p> 5 <p>「閉じる」か「背景」をクリックするとモーダルウィンドウを終了します。</p> 6 <p><a id="modal-close" class="button-link">閉じる</a></p> 7 <!-- モーダルウィンドウのコンテンツ終了 --> 8</div> 9 10<p><a id="modal-open" class="button-link">クリックするとモーダルウィンドウを開きます。</a></p> 11<!-- ここまでモーダルウィンドウ -->
CSS
1#modal-content{ 2 width:50%; 3 margin:1.5em auto 0; 4 padding:10px 20px; 5 border:2px solid #aaa; 6 background:#fff; 7 z-index:2; 8 position:fixed; 9 display:none; 10 overflow: auto; 11 max-height: calc(100vh - 1.5em); 12} 13 14.button-link{ 15 margin-left : 60px; 16 text-align:center; 17 -moz-border-radius: 5px; 18 -webkit-border-radius: 5px; 19 border-radius: 5px; 20} 21 22.button-link:hover{ 23 cursor:pointer; 24 color:#f00; 25} 26 27#modal-overlay{ 28 z-index:1; 29 display:none; 30 position:fixed; 31 top:0; 32 left:0; 33 width:100%; 34 height:120%; 35 background-color:rgba(0,0,0,0.75); 36 overflow: auto; 37} 38
JavaScript
1<!-- モーダルウィンドウ実装用 --> 2<script> 3jQuery(function($){ 4 5//モーダルウィンドウを出現させるクリックイベント 6$("#modal-open").click( function(){ 7 8 //キーボード操作などにより、オーバーレイが多重起動するのを防止する 9 $( this ).blur() ; //ボタンからフォーカスを外す 10 if( $( "#modal-overlay" )[0] ) return false ; //新しくモーダルウィンドウを起動しない (防止策1) 11 //if($("#modal-overlay")[0]) $("#modal-overlay").remove() ; //現在のモーダルウィンドウを削除して新しく起動する (防止策2) 12 13 //オーバーレイを出現させる 14 $( "body" ).append( '<div id="modal-overlay"></div>' ) ; 15 $( "#modal-overlay" ).fadeIn( "slow" ) ; 16 17 //コンテンツをセンタリングする 18 centeringModalSyncer() ; 19 20 //コンテンツをフェードインする 21 $( "#modal-content" ).fadeIn( "slow" ) ; 22 23 //[#modal-overlay]、または[#modal-close]をクリックしたら… 24 $( "#modal-overlay,#modal-close" ).unbind().click( function(){ 25 26 //[#modal-content]と[#modal-overlay]をフェードアウトした後に… 27 $( "#modal-content,#modal-overlay" ).fadeOut( "slow" , function(){ 28 29 //[#modal-overlay]を削除する 30 $('#modal-overlay').remove() ; 31 32 } ) ; 33 34 } ) ; 35 36} ) ; 37 38//リサイズされたら、センタリングをする関数[centeringModalSyncer()]を実行する 39$( window ).resize( centeringModalSyncer ) ; 40 41 //センタリングを実行する関数 42 function centeringModalSyncer() { 43 44 //画面(ウィンドウ)の幅、高さを取得 45 var w = $( window ).width() ; 46 var h = $( window ).height() ; 47 48 // コンテンツ(#modal-content)の幅、高さを取得 49 // jQueryのバージョンによっては、引数[{margin:true}]を指定した時、不具合を起こします。 50// var cw = $( "#modal-content" ).outerWidth( {margin:true} ); 51// var ch = $( "#modal-content" ).outerHeight( {margin:true} ); 52 var cw = $( "#modal-content" ).outerWidth(); 53 var ch = $( "#modal-content" ).outerHeight(); 54 55 //センタリングを実行する 56 $( "#modal-content" ).css( {"left": ((w - cw)/2) + "px","top": ((h - ch)/2) + "px"} ) ; 57 58 } 59 60} ) ; 61 62</script>
回答2件
あなたの回答
tips
プレビュー