2011-03-09 44 views
0

我需要一些編碼我的項目的幫助。你能幫我完成我的項目嗎?我需要創建.click事件錨,代碼將如下:用提交按鈕創建活動

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

不久,我想創造出產生點擊事件並找到進入目標搜索形式。

感謝您提前給予的幫助!

+0

請問這個「//點擊錨點標籤並輸入查找提交的目標。」意思?? – 2011-03-09 10:23:02

回答

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 2011-03-09 10:19:47

+0

@Avaz:我不確定你的意思。你可以再詳細一點嗎? – 2011-03-09 10:20:33

+0

我想添加到此代碼一個更多的功能,輸入應跳轉到一個錨點,並使其(我的意思是錨點)點擊 – Avaz 2011-03-09 10:23:13

0

假設你想重寫默認提交行爲和點擊的錨,而不是:

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