Jquery在一个div中获取输入值。

时间:2022-05-02 20:34:52

I have something like the following

我有一些类似的东西。

<div id="container">
      <ul id="name_list">
          <li class="name">
             <input type="hidden" class="name_val" value="5" />
          </li>
      </ul>
</div>

I am trying to get the value of the input. So far I have the following Jquery statment.

我试着得到输入的值。到目前为止,我有以下Jquery声明。

$("#container li.name input.name_val").val();

this does not work anyone know a better way?

谁知道这不是更好的方法吗?

3 个解决方案

#1


8  

You were having a typo in your input class name

输入类名中有一个错码

$("#container li.name input.name_val").val();

Also you can change your selector to something like

您还可以将选择器更改为类似的内容

$("#name_list > li.name > input:hidden.name_val").val();

#2


3  

Give your <input> either a name or an id. The you can get the value in either of these two ways:

给你的 <输入> 一个名字或一个id。你可以从这两种方法中得到它的值:

$('input[name=thename]').val()

or

$('input#theid').val()

#3


1  

Should it be

它应该是

var value = $('input.name_val').val();

You don't need to mention the other parts of the dom, just the area you are interested in.

您不需要提及dom的其他部分,只需提及您感兴趣的区域。

#1


8  

You were having a typo in your input class name

输入类名中有一个错码

$("#container li.name input.name_val").val();

Also you can change your selector to something like

您还可以将选择器更改为类似的内容

$("#name_list > li.name > input:hidden.name_val").val();

#2


3  

Give your <input> either a name or an id. The you can get the value in either of these two ways:

给你的 <输入> 一个名字或一个id。你可以从这两种方法中得到它的值:

$('input[name=thename]').val()

or

$('input#theid').val()

#3


1  

Should it be

它应该是

var value = $('input.name_val').val();

You don't need to mention the other parts of the dom, just the area you are interested in.

您不需要提及dom的其他部分,只需提及您感兴趣的区域。