2011-03-09 10 views
0

내 프로젝트 코딩에 도움이 필요합니다. 내 프로젝트를 끝내도록 도와 주시겠습니까? 내가 앵커 .click 이벤트를 만들 필요로 할 것이다 코드는 다음과 같습니다 제출 버튼으로 이벤트 만들기

$("form").submit(function() { 
    if ($("input:first").val() == "something") { 
    // anchor tag should be clicked and input should find submitted target. 
    } 
} 

은 곧 내가 클릭 이벤트를 생성하고 입력 대상을 찾아 탐색 양식을 만들려고합니다.

미리 도움을 주셔서 감사합니다.

+0

를이 무엇을 "// 앵커 태그를 클릭해야 입력 내용이 제출 된 대상을 찾아야합니다." 평균?? –

답변

1

질문을 올바르게 이해하면 양식에 입력 된 내용을 기반으로 페이지의 앵커로 이동하려고합니다. 여러 옵션이있는 경우

$('form').submit(function(e) { 
    e.preventDefault(); 
    if ($('input:first', this).val() == 'something') { 
    // anchor tag should be clicked and input should find submitted target. 
    window.location.hash = 'example-hash'; 
    } 
)}; 

, 당신은 switch 사용할 수 있습니다

$('form').submit(function(e) { 
    var val = $('input:first', this).val(), 
     hash; 
    e.preventDefault(); 
    switch (val) { 
    case 'foo': 
     hash = 'some-hash'; 
     break; 
    case 'bar': 
     hash = 'some-other-hash'; 
     break; 
    default: 
     hash = 'default-hash'; 
     break; 
    } 
    window.location.hash = hash; 
)}; 
+0

이 코드에 앵커 클릭 기능을 추가 할 수 있습니까? – Avaz

+0

@Avaz : 무슨 뜻인지 잘 모르겠습니다. 당신은 더 구체적 일 수 있습니까? –

+0

이 코드에 하나 이상의 함수를 추가하려면 입력이 앵커로 건너 뛰고 앵커를 클릭해야합니다. – Avaz

0

가정 기본 제출-동작을 무시하고 대신 앵커을 클릭합니다 :

$("form").submit(function(e) { 
    if ($("input:first").val() == "something") { 
     $("#anchorelementId").trigger('click'); 
     e.preventDefault(); // Prevents the submit-behavior from your form. 
    } 
} 
관련 문제