2012-05-05 3 views
1

두 개의 입력 필드와 두 개의 단추가 연속적으로 있습니다. 한 페이지에 3 개 이상의 행이있는 것과 같습니다. 각 행에 대해 두 개의 입력 필드에 값이있는 경우에만 두 개의 버튼을 활성화해야합니다. 나는 이드에게이 같은 2 개의 버튼을 주었다.조건에 따라 활성화/비활성화 단추가 두 번 경고를 표시합니다.

$('#first_link').click(function() {alert("Some info will come soon")}); 
$('#second_link').click(function() {alert("new info will come soon")}); 

을하지만이 경고 (세 개의 행 보여주는 3 알림) 모든 행오고 다음과 같이

<a href="#" style="margin: auto;" id="first_link"></a> 
<a href="#" style="margin: auto;" id="second_link"></a> 

JQuery와 나는했다. 해당 페이지의 전체 테이블에 대해 경고를 한 번만 표시하려면 어떻게합니까?

+0

u는 http://jsfiddle.net에서 전체 HTML 코드를 추가 할 수 있습니다. – Thulasiram

답변

0
$('#first_link').click(function(e) { 
    e.preventDefault(); // will prevent the link's default behavior 
    e.stopPropagation(); // will stop event bubbling 
    alert("Some info will come soon"); 
}); 

$('#second_link').click(function(e) { 
    e.preventDefault(); // will prevent the link's default behavior 
    e.stopPropagation(); // will stop event bubbling 
    alert("new info will come soon"); 
}); 

A different example.

+0

감사합니다. 그러나 각 행마다 다른 ID를 부여 할 수는 없습니다. 동적으로 새 행을 추가 할 수 있기 때문입니다. 그래서 나는 클래스 또는 ID에 링크를 줄지 혼란 스러웠다. – Raji

+0

다음과 같은 클래스를 사용할 수 있습니다. http://jsfiddle.net/heera/DqLwx/4/ –

+0

Thanks. 그것은 매우 유용합니다. – Raji

관련 문제