2013-05-20 68 views
0

我該如何製作一個簡單的html表單(只有名稱&電子郵件),當提交了一些jquery在頁面上找到特定鏈接並將它與來自形式到web服務器,其中一個腳本,然後從形式與鏈接 鏈接一起發送郵件到的電子郵件地址總是先從同樣的事情,看起來像:查找鏈接並通過電子郵件發送給我

http://www.exemple.com/abcd/1u3odjeo 
http://www.exemple.com/abcd/340fkdl4 

這是我得到了什麼現在爲表格:

<!DOCTYPE html> 
<html> 
<head> 
<script src="http://code.jquery.com/jquery-latest.js"></script> 
<script> 
$(document).ready(function(){ 

$('#submit').click(function(){ 

$.post("send.php", $("#mycontactform").serialize(), function(response) { 
$('#success').html(response); 
//$('#success').hide('slow'); 
}); 
return false; 


}); 

}); 
</script> 
</head> 
<body> 

<form action="" method="post" id="mycontactform" > 
<label for="name">Name:</label><br /> 
<input type="text" name="name" id="name" /><br /> 
<label for="email">Email:</label><br /> 
<input type="text" name="email" id="email" /><br /> 
<input type="button" value="send" id="submit" /><div id="success" style="color:red;"></div> 
</form> 
</body> 
</html> 

我錯過了鏈接抓取以及如何將其添加到發送電子郵件的腳本中。

感謝所有幫助

+0

這些鏈接將位於您的頁面上? – tymeJV

+0

這些鏈接是靜態的嗎?似乎將隱藏表單字段中的鏈接URL包含起來會更容易。 – David

回答

0

獲取網頁中的鏈接,其序列和發送之前插入的形式隱藏輸入。您也可以將鏈接值集中到序列化的字符串上:

$(document).ready(function() { 
    $('#mycontactform').on('submit', function(e) { 
     e.preventDefault(); 
     var link = $('a[href*="http://www.exemple.com/abcd/"]').attr('href'); 

     $('<input />', {type: 'hidden', name : 'link', value: link}); 

     $.post("send.php", $("#mycontactform").serialize(), function (response) { 
      $('#success').html(response); 
     }); 
    }); 
});