線上書籍

Home

JQUERY

  1. 母視窗表單 <!--廠商編號--> <div class='col-md-3'> <div class='form-group'> <label for='vendor' class='control-label'>廠商編號</label> <div class="input-group mb-2"> <input type="text" class="form-control" id="vendor" name='vendor' value="<{$row.vendor}>" readonly> <div class="input-group-prepend"> <div class="input-group-text"> <a href="javascript:void(0)" class="vendorWin" > ... </a> </div> </div> </div> </div> </div>   <!--廠商名稱--> <div class='col-md-3'> <div class='form-group'> <label for='vendor_title' class='control-label'>廠商名稱</label> <div class="input-group mb-2"> <input type="text" class="form-control" id="vendor_title" name='vendor_title' value="<{$row.vendor_title}>" readonly> <div class="input-group-prepend"> <div class="input-group-text"> <a href="javascript:void(0)" class="vendorWin" > ... </a> </div> </div> </div> </div> </div>

     

  2. 母視窗按鈕 //廠商視窗 $(".vendorWin").click(function(){ vendorWin('purchase.php?op=vendorWin',300,300); });

     

  3. 母視窗函數 //子視窗函數 function vendorWin(imgName,imgH,imgW) { screenWidth = screen.width;//取得螢幕寬度 rightPosition = screenWidth - imgW - 20; // 計算視窗右上位置 mywin=window.open("","","left="+ rightPosition +",top=100,width=" + imgW + ",height=" + imgH + ",location=no"); mywin.location.href = imgName + "&sn=" + document.getElementById('vendor').value; }

     

  4. 從子視窗設定母視窗的元素(後來沒用) var vendor = document.getElementById('vendor'); window.opener.document.getElementById('vendor').value = vendor.value; window.opener.document.getElementById('vendor_title').value = vendor.options[vendor.selectedIndex].text; //window.opener.getAjaxVendor(sn);
     
  5. 子視窗函數 <script> function senddata() { var vendor = document.getElementById('vendor'); var sn = vendor.value; var old_sn = window.opener.document.getElementById('vendor').value; if(window.opener.document && sn != old_sn){ window.opener.getAjaxVendor(sn);//run 母視窗的方法 } window.close();//結束子視窗 } </script>

     

  6. 子視submit <select name='vendor' id='vendor' class='form-control' size='5'> $option </select> <input type='button' value='送出' onClick='senddata()' />

     

  7. 參考 modules/umg_stk/purchase.php -> vendorWin($sn)、getAjaxVendor($sn)