我循环了我的 html,并希望在用户单击按钮时获得特定的字段值。我很想检索正确的值,请帮帮我。
<div id="tabs1">
<table>
{foreach from=$this->products item=p}
<tr>
<td><div class="tabs-product">
<div>
<input type='hidden' id='item' name='item' value='{$p.name}'/>
<input type='hidden' id='price' name='price' value='{$p.price}'/>
<button class="shareButton" onclick='post(); return false;'>Share</button>
</div></td></tr>
{/foreach}
</table></div>
<script>
function post() {
var item = $(this).parent("tabs-product").attr("input");//this cause undefined
var price = $('#price').val(); //this method only get first value
alert(item + price);
}
</script>