我有一些阻力和可排序的ul .... 现在我需要设置隐藏输入字段" area []"值 ul属性位置
的相同值<ul id='sortlistThree' location='1' class='connectMe sort'>
<li>
<form class='sort'>
<input type='hidden' name='area[]' class='dienstplan' data='getform' value='' />
</form>
</li>
<li>
<form class='sort'>
<input type='hidden' name='area[]' class='dienstplan' data='getform' value='' />
</form>
</li>
</ul>
<ul id='sortlistThree' location='2' class='connectMe sort'>
<li>
<form class='sort'>
<input type='hidden' name='area[]' class='dienstplan' data='getform' value='' />
</form>
</li>
</ul>
<ul id='sortlistThree' location='3' class='connectMe sort'>
<li>
<form class='sort'>
<input type='hidden' name='area[]' class='dienstplan' data='getform' value='' />
</form>
</li>
</ul>
答案 0 :(得分:1)
使用JQuery你可以这样做,我删除了hidden
,这样你就可以看到发生了什么。
$('input[name="area[]"]').each(function(){
$(this).attr('value',$(this).closest('ul').attr('location'));
})
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul id='sortlistThree' location='1' class='connectMe sort'>
<li>
<form class='sort'>
<input name='area[]' class='dienstplan' data='getform' value='1' />
</form>
</li>
</ul>
<ul id='sortlistThree' location='2' class='connectMe sort'>
<li>
<form class='sort'>
<input name='area[]' class='dienstplan' data='getform' value='1' />
</form>
</li>
</ul>
<ul id='sortlistThree' location='3' class='connectMe sort'>
<li>
<form class='sort'>
<input name='area[]' class='dienstplan' data='getform' value='1' />
</form>
</li>
</ul>
&#13;