2012-10-16 83 views
0

我試圖打開從RSS提要進入對話框的鏈接。我正在嘗試從here得到的以下代碼。該鏈接不會打開對話框。任何建議,我做錯了。 感謝在jQuery UI對話框中加載動態鏈接

$(document).ready(function() { 
       $('a#URLLoad').live('click', function(e) { 
        e.preventDefault(); 
        var page = $(this).attr("href") 
        var pagetitle = $(this).attr("title") 
        var $dialog = $('<div></div>') 
        .html('<iframe style="border: 0px; " src="' + page + '" width="100%" height="100%"></iframe>') 
        .dialog({ 
         autoOpen: false, 
         modal: true, 
         height: 625, 
         width: 500, 
         title: pagetitle 
        }); 
        $dialog.dialog('open'); 
       }); 

      }); 

    <li class="ui-state-default"> 
<a class="URLLoad" href="http://feeds.arstechnica.com/~r/arstechnica/index/~3/4UlQiQB2n54/">New Xbox interface brings Windows 8 "Metro" style to the console</a></li> 

UPDATE:http://jsfiddle.net/daxnp/

+1

看看[我可以提出一個不同的方法來組織呢?( http://jsfiddle.net/3E6Vp/)。此外,沒有理由阻止autoOpen在創建後直接調用它,這是不必要的冗餘。 – Ohgodwhy

+1

其工作正常。這裏是小提琴http://jsfiddle.net/zQdb4/1/ –

+0

沒有爲我工作 – jsp

回答

1

您使用的類未ID改變這樣

$(document).ready(function() { 
       $('a.URLLoad').live('click', function(e) { 
        e.preventDefault(); 
        var page = $(this).attr("href") 
        var pagetitle = $(this).attr("title") 
        var $dialog = $('<div></div>') 
        .html('<iframe style="border: 0px; " src="' + page + '" width="100%" height="100%"></iframe>') 
        .dialog({ 
         autoOpen: false, 
         modal: true, 
         height: 625, 
         width: 500, 
         title: pagetitle 
        }); 
        $dialog.dialog('open'); 
       }); 

      }); 

您需要更改$('a#URLLoad')$('a.URLLoad')

更新您的代碼:

我已經更新您的提琴在這裏Demo

我認爲問題是,你還沒有包括jQuery UI的參考和CSS

+0

那還沒有加載URL到對話框 – jsp

+0

你可以做一個小提琴 – rahul

+0

是現在爲你工作 – rahul