jQuery « Как получить значение поля формы с помощью jQuery

Здравствуйте!

Задача в следующем:

На странице есть формы (каждая из которых появляется в всплывающем окне при клике на соответствующую кнопку), отличающиеся лишь по id input-а.

Как получить доступ с помощью jQuery к value определенной формы (после ввода)?

/** * GeSHi (C) 2004 - 2007 Nigel McNie, 2007 - 2008 Benny Baumann * (http://qbnz.com/highlighter/ and http://geshi.org/) */ .html4strict.geshi_code {font-family:monospace;} .html4strict.geshi_code .imp {font-weight: bold; color: red;} .html4strict.geshi_code .kw2 {color: #000000; font-weight: bold;} .html4strict.geshi_code .kw3 {color: #000066;} .html4strict.geshi_code .es0 {color: #000099; font-weight: bold;} .html4strict.geshi_code .br0 {color: #66cc66;} .html4strict.geshi_code .sy0 {color: #66cc66;} .html4strict.geshi_code .st0 {color: #ff0000;} .html4strict.geshi_code .nu0 {color: #cc66cc;} .html4strict.geshi_code .sc-1 {color: #808080; font-style: italic;} .html4strict.geshi_code .sc0 {color: #00bbdd;} .html4strict.geshi_code .sc1 {color: #ddbb00;} .html4strict.geshi_code .sc2 {color: #009900;} .html4strict.geshi_code span.xtra { display:block; }

<div class="form-item" id="edit-log-wrapper">
 <label for="edit-log">login: </label>
 <input type="text" name="log" id="edit-log" value="" class="form-text" />
</div>

<div class="form-item" id="edit-log-1-wrapper">
 <label for="edit-log-1">login: </label>
 <input type="text" name="log" id="edit-log-1" value="" class="form-text" />
</div>

<div class="form-item" id="edit-log-2-wrapper">
 <label for="edit-log-2">login: </label>
 <input type="text" name="log" id="edit-log-2" value="" class="form-text" />
</div>
 


Такой вот простой вроде вопрос, но не знаком с данной тематикой и первичный просмотр документации не прояснил ответа.

Спасибо.

1 ответов


Не очень понял вопрос, поэтому как-то так:


$(function() {
 $('.form-text').click(function() {
  var value = $(this).val();
  alert(value);
 });
});
 

Вопрос решил так:

$('input[name=log]', this.form).val()