2011-02-02 8 views
4

jqueryを使用してiframeを下に追加しようとしていますが、リンクをクリックしても何も起こりません。jQueryを使用してiframeを追加しようとしています

<head> 

    <script type="text/javascript" 
      src='//ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.js'></script> 

    <script type="text/javascript"> 

     function fun(){ 
      $('<iframe />'); // Create an iframe element 
      $('<iframe />', { 
       name: 'frame1', 
       id: 'frame1', 
       src: 'http://www.programmingfacts.com' 
      }).appendTo('body'); 

    </script> 

    </head> 

    <body> 

     <a href="#" onclick="fun()">clica</a> 

    </body> 

</html> 

答えて

7

私の推測では、あなたの関数fun()閉じ括弧を閉鎖いけないということですか?動作するはず

function letsHaveFun(){ 
    $('body').append('<iframe src="http://www.programmingfacts.com" name="frame1" id="frame1"></iframe>'); 
} 

:}

2
はにあなたの関数を変更し

7

これを試してみてください:

<html> 
    <head> 
     <script type="text/javascript" src='http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.js'></script> 
     <script type="text/javascript"> 
      $(document).ready(function() { 
       $(".submit").click(function() 
       { 
        $('<iframe />'); // Create an iframe element 
        $('<iframe />', { 
         name: 'frame1', 
         id: 'frame1', 
         src: 'http://www.programmingfacts.com' 
        }).appendTo('body'); 
       }); 
      }); 
     </script> 
    </head> 
    <body> 
     <a href="#" class="submit">clica</a> 
    </body> 
</html> 
関連する問題