Если вы дадите всем своим ссылкам класс .number
:
$("a.number").click(function(e) {
e.preventDefault();
window.location.href = 'process.php?btn=' + $(this).text();
});
<a class="number" href="#">1</a>
<a class="number" href="#">2</a>
...
Это, кажется, тот тип вещей, который лучше всего делать на стороне сервера, например, когда сервер рендерит каждый href
с правильными значениями параметров. Я предполагаю , что не вариант в вашем случае.
РЕДАКТИРОВАТЬ: Асинхронность, как запрошено:
$("a.number").click(function(e) {
e.preventDefault();
// fill up div with ID="results" with content from server
$("#results").load("process.php", { btn: $(this).text() }, function() {
// callback to do something once the content has loaded
// (perhaps not needed)
});
});
<div id="results"></div>
...
<a class="number" href="#">1</a>
<a class="number" href="#">2</a>
...
См. $.load
и $.ajax
.