2013-04-02 19 views
1

是我的JavaScript文件的一部分從動態創建的span標籤發送數據到PHP下面

$("#imgBox").append('<div id="inner_div_electric" style="position: relative; top: '+innerDivElectricTop+'px; left: '+innerDivElectricLeft+'px;width:'+innerDivElectricWidth+'px;height:'+innerDivElectricHeight+'px;"></div>'); 
    for(var i=1; i<=sidewalls; i++) 
    { 
      for(var j=1; j<=backwalls; j++) 
      { 
       var newDiv = "<span id='droppable"+i+""+j+"' onclick='changeText(this.id);' class='droppable_class' style='width:"+(cellWidth-2)+"px; height:"+(cellHeight-2)+"px;border:1px dotted red;display:inline-block;margin:0px;padding:0px;float:left;'></span>"; 
       $("#inner_div_electric").append(newDiv); 
      } 
    } 

這裏imgBox是一個div,並在該分區時動態創建的跨度來生成該div sqare盒。

$('.droppable_class').html(''); 
if($('#'+id).html('')) 
{ 
    $('#'+id).html('<font face="calibri" color="red"><b>OUTLET</b></font>'); 
} 

這是在單擊的範圍內生成文本'OUTLET'的代碼。我需要發送div,因爲它是從這個javascript文件到php生成包含sqare框的特定圖的pdf,並且一個特定的span包含文本'OUTLET'。

任何想法如何實現它?

由於

+0

我敢打賭,這是無法實現的......如果你使用'輸出緩衝'處理輸出並將其捕獲到一個變量並將其傳遞給PDF創建服務,那麼JavaScript代碼將不會執行只是一個客戶端腳本。您必須使用PHP生成相同的HTML才能將其輸出到PDF創建服務... – shadyyx

回答

0

這一個是容易的,只是輸入動態,並把它們添加到一種形式;那麼,你可以用$('#formid')手動調用提交表單。

另外,如果您想使用Javascript,您可以覆蓋.submit()。想想這個:

<span> 
<form id="sform"> 
<input name="someDynamicallyCreatedInput" /> <!-- use this instead of a div (or just copy your div to here)--> 
</form> 
<script> 
$('#sform').submit(function(e){//function to be called before form is sent 
//if you want to manually send it, wihtout using default form behavior... just put this: 
//e.preventDefault(); 
//then do some ajax here, or heck, just let the form send the data if you are changing pages. 
//however, if you want to download a pdf, you may want to just send a get request using href... 
}); 
</script> 
</span> 

導出爲pdf只需要使用php header()函數設置Content-Type。

來源: http://api.jquery.com/submit/ http://php.net/manual/en/function.header.php //這裏有一個很好的例子爲PDF文件。

+0

不確定這是否是您的問題的答案。我可能誤讀了。 –