0

我有一个从 PHP 填充的 div 我正在尝试将 div 中的所有输入框绑定到变量,(我不希望使用序列化)如何使用 Jquery 选择每个输入框并将其绑定到变量,例如

var location_id = $('#Wednesday').find('input').nth-child(0);
var static_id  =$('#Wednesday').find('input').nth-child(1);

那种性质的东西谢谢!

<div id='Wednesday' class='ui-widget-content ui-state-default' name='' value=''>  ";

echo "<input name='".$day."_".$locationid."_locationID' value='".$locationid."'  type='hidden'> ";
echo "<input name='".$day."_".$locationid."_static' value='".$static."'  type='hidden'> ";
echo "<input name='".$day."_".$locationid."_primary' value='".$first_always."' type='hidden'> ";
echo "<input name='".$day."_".$locationid."_all_locations' value='".$all_locations."' type='hidden'> ";

</div>
4

3 回答 3

1

As a side note (since you already have your answer), any time I see input names of a form similar to what you have:

'name="' . $day . '_' . $location_id . '_locationID"'

It screams out to me that this might be a case where you should be using array-style form inputs like this:

'name="locationID[' . $day . '][' . $location_id . ']"'

That way in PHP, you already have a nice array built for you in $_POST and you don't need to explode() to build arrays out of all the input fields.

于 2013-01-22T01:29:24.283 回答
1
var inputs = $('#Wednesday').find('input');

var location_id = inputs.eq(0).val();
var static_id  = inputs.eq(1).val();
于 2013-01-22T00:51:36.693 回答
0

使用.eq而不是.nth-child().

于 2013-01-22T00:46:15.743 回答