jquery
<script type="text/javascript">
$(document).ready(function(){
  $(".change").each (function(i){
  $(this).on("click", {x:(i+1)}, function(event){
  
  alert( event.data.x);
  
   });
   });
});
</script>
想請問我用for迴圈執行以下這行,每個id="change'.$day.'",請問要怎麼傳遞到jquery的
#change 謝謝..兩段語法在同頁面
$day=1;
 
        for($x=0;$x<=41;$x++){
    	
        	
    	     echo'<div data-toggle="modal" data-target="#exampleModal" data-whatever="@getbootstrap" id="change'.$day.'" style="background-color:'.$color.';opacity:'.$dark.';width:120.6px;height:160px;float:left;border:#FFFFFF 1px solid;">'."[$day]".'<p id="window'.$day.'">1233</p></div>';
    	    
    	     
    	     ++$day;
 
    	
    	
    	}
boostrap資料
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header" style="background-color:#88AA00">
        <h5 class="modal-title" id="exampleModalLabel" >借教室登記</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">×</span>
        </button>
      </div>
      <div class="modal-body">
        <form>
          <div class="form-group">
            <label for="recipient-name" class="col-form-label">姓名:</label>
            <input type="text" class="form-control" id="recipient-name">
          </div>
          <div class="form-group">
            <label for="message-text" class="col-form-label">借用時間:</label>
            <textarea class="form-control" id="message-text"></textarea>
          </div>
        </form>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Send message</button>
      </div>
    </div>
  </div>
</div>
個人建議使用類似 handlebar.js 的 template library, 把 html 包起來,然後透過 ajax 自 PHP 取得一個陣列,再套用在 html 上,程式就會比較易維護,且減少錯誤發生的機率。
可以參考 http://handlebarsjs.com/