2014-03-05 3 views
0

C#을어떻게 동적으로 생성 된 버튼

foreach (DataRow Row in oDs.Tables[0].Rows) 
        { 
         LitPreferances.Text += "<Li ID=LI_" + Row["pk_Preference_Branch_ID"].ToString() +"_"+ Row["pk_Preference_BranchType_ID"].ToString() +">" + Row["Branch_Name"].ToString() + "&nbsp;&nbsp;<a href='#' title='delete' class='itemDelete' onclick='return RemoveBranch();' tooltip='Remove Branch'>Remove</a></Li>"; 
        } 

내가 ODS 데이터 세트에 배치됩니다 몇 가지 이름을 데 나는 또한 특정 지점의 앞에 제거 버튼을 만드는 오전 위해 자바 스크립트를 사용합니다. 제거 버튼에는 예상대로 작동하지 않는 자바 스크립트가 있습니다.

자바 스크립트

function RemoveBranch() { 
     $('.itemDelete').live('click', 
    function() { 
     $(this).closest('Li').remove(); 
    } 
); 
     return false; 
     } 

그 보여주는 오류 개체가

+0

'on' inst를 사용하십시오. ead of live' – rps

답변

0

라이브 사용을 .on을 depriciated되는 속성 또는 '라이브'메소드를 지원하지 않는 :

<html> 
    <head> 
     <script src="http://code.jquery.com/jquery-1.11.0.min.js"></script> 
      . 
      . 
      . 
    </head> 
</html> 

function RemoveBranch() { 
     $('body').on('click','.itemDelete',function() { 
     $(this).closest('Li').remove(); 
    }); 
return false; 
}  
+0

저는 여전히 같은 plateform에 있습니다. JavaScript 런타임 오류 : 객체가 'on'속성 또는 메서드를 지원하지 않습니다. –

+0

jQuery를 사용하고 있습니까 ?? 위의 코드에 대한 –

+0

JQuery를 사용해야합니다. –

0
I got one solution over there, just simply used 

function RemoveBranch() { $("#ULPreferences li").click(function() { 
$(this).remove(); }); } 
관련 문제