jquery obtiene el valor usando el nombre de la clase

I am trying to get the value of an input text field based on its class name through jquery.

el HTML es:

<form>
  <input type="text" id="datePicker" style="display: none;">
  <div class="dp_wrapper dp_input_6">
    <div class="dp_tagBox">
      <span class="dp_tag dp_tag_day">11</span>
      <span class="dp_tag dp_tag_month">Jun</span>
      <span class="dp_tag dp_tag_year">2009</span>
      <input type="text">
    </div>
  </div>
  <input type="button" onclick="GetContents()" value="submit">
</form>

El jquery es:

var myValue=$('.dp_tag dp_tag_day').val()

Pero myValue is coming up undefined. Does anyone know why?

preguntado el 10 de marzo de 12 a las 12:03

4 Respuestas

var days_as_nums = parseInt($('.dp_tag_day', '.dp_input_6').text(), 10);

respondido 11 mar '12, 13:03

Added the base to your answer. - epascarello

Simply add + to get value like below.

var myValue = +$('.dp_tag dp_tag_day').val()

Respondido 03 Oct 13, 13:10

$('.dp_tag dp_tag_day') es un <span>-Tag and you haven't the option .val(). Use esto en su lugar:

var myValue=$('.dp_tag.dp_tag_day').html()

Esto volverá 11.

respondido 10 mar '12, 12:03

You are probably trying to get the text value of the span which is number of days in your case:

var myValue = $('.dp_tag.dp_tag_day').text();

respondido 10 mar '12, 12:03

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.