2011-12-21 89 views
0

需要有人來幫助我的the jQuery Dialog plugin by Eric Martin - Simple ModeljQuery的對話框 - 從PHP傳遞變量值jQuery函數

我有一個包含我想傳遞一個值到另一個頁面的鏈接PHP頁面。因此,我需要幫助如何將值傳遞給包含下面的頁面URL var的jQuery腳本?

Profile.php

<div id='basic-modal'> 
     <a href='#' class='basic'>Jquery Dialog Demo</a> 
</div> 

注:當我點擊鏈接,它會調用jQuery的基本模型DIV從Basic.js

Basic.js

jQuery(function ($) { 

    // Load dialog on click 
    $('#basic-modal .basic').click(function (e) { 

    // Display an external page using an iframe 
var src = "http://365.ericmmartin.com/"; 
$.modal('<iframe src="' + src + '" height="450" width="830" style="border:0">', { 
    closeHTML:"", 
    containerCss:{ 
     backgroundColor:"#fff", 
     borderColor:"#fff", 
     height:450, 
     padding:0, 
     width:830 
    }, 
    overlayClose:true 
}); 

     return false; 
    }); 
}); 

注:在上面,我想var src包含變量值,我 s應該將其從Profile.php中傳遞出來。我應該怎麼做?

+0

您的問題還不清楚。顯示包含您想要傳遞的值的代碼 – Chibuzo 2011-12-21 05:23:24

+0

嗨Chibuzo,感謝您的回覆。這裏是我想傳遞給Basic.js的頁面鏈接變量的示例=> http://domain.com/Poll.php?id=1&validate=yes – Ray 2011-12-21 05:27:42

+0

嗨Chibuzo,基本上,Profile.php應該看起來像這個:

Jquery Dialog Demo Vice versa, on the Basic.js, the var src should contain the link from the Profile.php instead. Please advice and thanks
Ray 2011-12-21 05:31:00

回答

2

更改Profile.php略:

<div id='basic-modal'> 
     <a href='http://localhost/Poll.php?id=1&validate=yes' class='basic'>Jquery Dialog Demo</a> 
</div> 

變化Basic.js像這樣:

jQuery(function ($) { 

     // Load dialog on click 
     $('#basic-modal .basic').click(function (e) { 
     e.preventDefault(); 

     // Display an external page using an iframe 
     var src = $(this).attr('href'); 
     $.modal('<iframe src="' + src + '" height="450" width="830" style="border:0">', { 
      closeHTML:"", 
      containerCss:{ 
       backgroundColor:"#fff", 
       borderColor:"#fff", 
       height:450, 
       padding:0, 
       width:830 
      }, 
      overlayClose:true 
     }); 


      return false; // not sure why you're doing this 
     }); // end of click handler 




    }); // end of document.ready 
+0

嗨傑克,感謝代碼並向我展示正確的方向。它現在有效。非常感激! – Ray 2011-12-21 05:39:20

+0

偉大 - 關心標記這是接受的答案? – 2011-12-21 05:40:11

+0

我應該在哪裏標記它以接受答案。新的這個stackoverflow ..乾杯 – Ray 2011-12-21 05:44:36

1
e.preventDefault(); 
var src = $(e.target).attr("href"); 
+0

嗨Fenec,感謝代碼。它現在有效。非常感激! – Ray 2011-12-21 05:39:41

+0

嗨Fenec,試圖在這個線程投票,但系統返回給我以下錯誤「投票要求15聲望」。因此,我無法做到,但真的很感謝你的幫助。 – Ray 2011-12-21 05:52:07