2014-12-29 5 views
1

attr에 추가 OnClick 어떻게이 두통을 가지고슬래시가 JQuery와 아약스 피드에서 제거,

강령 :

<script type="text/javascript" language="javascript"> 
    $(document).ready(function(){ 
     $("#dvContent").append("<ul class='list'></ul>"); 
     $.ajax({ 
      type: "GET", 
      url: "file.xml", 
      dataType: "xml", 
      success: function(xml){ 
       $(xml).find('entry').each(function(){ 
       var sTitle = $(this).find('title').text(); 


     // HERE I Need to add onClick attr 
     // Por example (added to <a>) 
     $("<li></li>").html("<a onclick='example('https://yahoo.com/');' href='http://google.com/'>" + sTitle + '</a>').appendTo("#dvContent ul"); 

     // but I'ts the Result: (with-out Slash and [']) 

     $("<li></li>").html("<a onclick="example(" https:="" www.yahoo.com=""');'" href='http://google.com/'>" + sTitle + '</a>').appendTo("#dvContent ul"); 


       $("<li></li>").html("<a href='http://google.com/'>" + sTitle + '</a>').appendTo("#dvContent ul"); 
      }); 
      }, 
      error: function() { 
      alert("An error occurred while processing XML file."); 
      } 
     }); 

    }); </script> 

19 함께 aprox<a> 내가 [onclick='example('http://yahoo.com/');']

를 추가 할 필요가 라인에서

어떻게 해결할 수 있습니까?

나는

답변

0

사용이 사용할 수있는

$("<li></li>").html("<a class='someclass' href='http://google.com/'>" + sTitle + '</a>').appendTo("#dvContent ul"); 

jQuery 코드

$('.someclass').click(function(){ 
alert('test'); 
}); 
을 슬래시를 삭제하고 인용되는 실현