2014-11-21 102 views
0
function click1(a) 
{ 
var srcdivid =$(a).closest('div').attr('id'); 

$("#pagetemplate").dialog("open"); return false; 
} 

在這裏,我得到的價值srcdivid,我有這個值傳遞給上述對話。它有可能嗎?我們如何將值傳遞給對話框小部件?

我的對話窗口小部件的代碼如下

<?php 
$this->beginWidget('zii.widgets.jui.CJuiDialog', array(
    'id'=>'pagetemplate', 
     'options'=>array(
     'title'=>'Page Template', 
     'autoOpen'=>false, 
     'modal'=>true, 
     'width'=>1000, 
     'height'=>300  
    ), 
));?> 
<input type="hidden" name="padeidvalue" id="padeidvalue"> 
<?php if(count($templatemodel) > 0){ 
    for($i=0;$i<count($templatemodel);$i++){ 
echo "<div class='temp-thumb'><a class='".$templatemodel[$i]['template_image_name']."' onclick='addtemplate(".$templatemodel[$i]['page_template_id'].");' href='#'></a></div>"; 
    } 

}else{ 
    echo "<p>Opps!. No Templates Found></p>"; 
}?> 

<?php $this->endWidget('zii.widgets.jui.CJuiDialog');?> 

這裏我所說的addtemplate功能。它的定義如下

function addtemplate(params){ 

var srcdivid =""; 
alert(srcdivid); 
alert(params); 
$.ajax({ 
    url:baseURL+"/index.php/MyAlbums/AddTemplatesToDiv", 
    type:'POST', 
    data:{"templateid":params,"divid":"srcdivid" }, 
    success:function(data){ 
     $("#"+srcdivid).html(data.template); 
     $("#pagetemplate").dialog("close"); 
     $(".imgborderclass").removeClass("imgborderclass"); 
     addClass(); 
     addComm(); 
    },  
}); 
} 

我必須得到srcdivid在這個addtemplate函數,我通過點擊功能。請幫助我..

回答

0

使用data() jQuery的方法。

function click1(a) { 
    var srcdivid =$(a).closest('div').attr('id'); 
    $("#pagetemplate").data('srcdivid', srcdivid); 
    $("#pagetemplate").dialog("open"); return false; 
} 

function addtemplate(params) { 
    var srcdivid = $("#pagetemplate").data('srcdivid'); 
    alert(srcdivid); 
    ... 
} 
相關問題