开发者

How can I get the hidden value?

I have one Input.hidden in a foreach, how can I get the different values?

<% foreach (var archivos in Model.archivosAdjuntos) { %>
  <div class="myDiv">
    <%= Html.ActionLink( NAME OF A FILE )%> &nbsp;&nbsp;       
    <input id="DELETE" name="DELETE" value="DELETE" type="button" class="DELETE"/>
    <br /><br />
    <%:Html.HiddenFor(model=>hidden id of a file, new { @class="hidden_hiddenFile"}) %>  
  </div>
<% } %>

I try to get the hidden value:

  $(".DELETE").click(function () {
 开发者_开发百科       alert($(this).parent().next().attr("value"));

but the result of the alert is UNDEFINED.


$(this).parent() is going to get you the myDiv div.

.next() will get the next myDiv div.

.attr("value") won't work, because the div doesn't have a value.

I'm assuming you want the hidden value that's next to the input you clicked on, not the next input.

You should do something like:

$(this).next('.hidden_hiddenFile').attr("value")


I didn't test this, but you might have missed calling children() on the parent. Maybe something like this would work:

alert($(this).parent().children('.hidden_hiddenFile').attr('value'));

Edit: Rocket's selector makes more sense, you don't actually need to select the parent first.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜