开发者

ASP.Net MVC - get selected <tr> row from a table thru jquery

开发者 https://www.devze.com 2023-03-01 03:09 出处:网络
cshtml code: foreach (Frame frame in Model.ListFrames) { <tr class=\"clickME\" title=\"fred\"> <inputtype=\"hidden\" name=\"NameId\" value=\"@frame.Id\" style=\"border:0\"/>

cshtml code:

        foreach (Frame frame in Model.ListFrames)
        {      
            <tr class="clickME" title="fred">
                <input  type="hidden" name="NameId" value="@frame.Id" style="border:0"/>
                <input  type="hidden"  name="TypeId" value="@frame.Type" />
                <input  type="hidden" name="thirdone" value="@frame.Id" />
                <td>
                    <a href="#" class="up"><img src="../../Content/img/up.jpg"  style="border:0px" alt="Move up" /></a>
                    <a href="#" class="down"><img src="../../Content/img/down.jpg"  style="border:0px" alt="Move down"/></a>        
                </td> 

                @if(frame.Type == string.Empty)
                {   <td>
                        <textarea rows="1" cols="15"  id="Name" name="Name"  onclick="display('@frame.Id', this); LoadImage(this);" 
                            onchange="LoadImage(this);" onkeyup="LoadImage(this);" style="height:20px">@frame.Name</textarea>

                    </td>

                    <td> 
                        @(Html.DropDownList("MyFont", new SelectList((IEnumerable)ViewData["Font"], "Text", "Value", @frame.Font), 
                            new { onclick="LoadImage(this);", onchange = "LoadImage(this);" }))
                    </td>
                    <td> 
                         @(Html.DropDownList("MyColor", new SelectList((IEnumerable)ViewData["Color"], "Text", "Value", @frame.Color), 
                            new { onclick="LoadImage(this);" , onchange = "LoadImage(this);" }))
                    </td>
                    <td>
                         @(Html.Telerik().NumericTextBox()
                               .Name("onTime" + frame.Id)
                               .MinValue(0)
                               .Value(frame.OnTime)
                               .InputHtmlAttributes(new { style = "width:50px;" })
                               )
                    </td>
                    <td>
                        @(Html.DropDownList("onTransition"+frame.Id,
                            new SelectList((IEnumerable)ViewData["Transition"], "Value", "Text", @frame.Transition), 
                            new {onclick="LoadImage(this);"})
                            )
                    </td>


                }
                else
                {
                  <td colspan="3">
                  <textarea rows="1" cols="15"  id="Name" name="Name" readonly="true" onclick="display('@frame.Id', this);" style="height:20px">@frame.Name</textarea>
                    </td>
                     <td style="display:none;"> 
                        @(Html.DropDownList("MyFont", new SelectList((IEnumerable)ViewData["Font"], "Text", "Value", @frame.Font), 
                            new { onclick = "LoadImage(this);", onchange = "LoadImage(this);" }))
                    </td>
                    <td style="display:none;"> 
                         @(Html.DropDownList("MyColor", new SelectList((IEnumerable)ViewData["Color"], "Text", "Value", @frame.Color), 
                            new { onclick = "LoadImage(this);", onchange = "LoadImage(this);" }))</td>

                }

        开发者_Go百科}

I am trying to get the frame.Id value for the currently selected row thru a jquery command. I am trying to get it outside of the itself. ie when a submit button is clicked elsewhere on the page. I have defined the following function:

    $(".flashing").click(function () {
        var tr = $(this).find(".clickME");
        alert(tr.children.length);

    });

this works - in so much as I believe I find my correct tag, but not sure if it's the one that's actually currently selected or not. I always get a value of 2 for children.length but not really sure what that's pointing to.

so, is it possible in the above function to determine (ultimately) the @frame.Id value stored in the currently selected tag.

I'm very new to this and this code has been written by someone else so I am just trying to find my way.

TIA

Jason


From what I can see you have a hidden field inside the tr containing the frame.Id as value. So you could try reading the value from this hidden field:

$('.flashing').click(function () {
    var tr = $(this).find('.clickME');
    var id = $(tr).find('input[name="NameId"]').val();
    alert(id);
});
0

精彩评论

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