Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/398.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 选择时,从表TD内的输入字段中检索值_Javascript_Jquery_Html_Twitter Bootstrap_Jsp - Fatal编程技术网

Javascript 选择时,从表TD内的输入字段中检索值

Javascript 选择时,从表TD内的输入字段中检索值,javascript,jquery,html,twitter-bootstrap,jsp,Javascript,Jquery,Html,Twitter Bootstrap,Jsp,我想知道当点击TD时,是否有办法从TD内的输入字段中检索值 我设法得到了其中的一个值,但当我按下另一行时,它没有改变 例如,这是我的JSP,它导致2个TD: <div class="col-md-6"> <table class="table fixed"> <thead>

我想知道当点击TD时,是否有办法从TD内的输入字段中检索值

我设法得到了其中的一个值,但当我按下另一行时,它没有改变

例如,这是我的JSP,它导致2个TD:

               <div class="col-md-6">
                        <table class="table fixed">
                            <thead>
                                <tr>
                                    <th>Choose what account you want to login to</th>
                                    <td align="right"><strong></strong></td>
                                </tr>
                            </thead>
                            <c:forEach var="i" begin="0" end="${roleList.getSize() -1}">
                                <tbody id="extend">
                                    <tr data-toggle="collapse123" class="clickableRow spaceUnder" nowrap="true" data-target=".demo1" id="1">
                                        <td class="AlignLeft" nowrap="true" style="border-right: 0px;">
                                            <label for="important"style="display: inline !important">${roleList.getFirstName(i)} ${roleList.getLastName(i)}</label>
                                        </td>
                                        <td align="right" class="AlignRight" style="border-left: 0px;">
                                            <input type="hidden" id ="roleId" name="chosenRole" value="${roleList.getClientId(i)}">
                                        </td>
                                    </tr> 
                                </c:forEach>

                        </table>
                        <input type="hidden" id ="roleClicked" name="roleClicked" value="">
                    </div>
如何选择单击的TD的inputfield值

编辑:我回来了是正确的,尽管我不得不把我的输入字段从第二个TD移到第一个TD,这对我来说一点问题都没有,反正它是隐藏的

你需要使用

而不是-val方法返回或设置选定元素的value属性

$("#roleClicked").text();

解决办法应该是这样

$( document ).ready(function() {

            $("#extend td").click(function () {
                $("#roleClicked").val($(this).find("input").val());
            });
    });
或者用于基于ajax的加载

$( document ).ready(function() {
    $( "#extend" ).on( "click", "td", function() {
        $("#roleClicked").val($(this).find("input").val());
    });
});

好的,谢谢,我现在做了$roleClicked.val$roleId.val;但是现在我得到了相同的ID,即使我点击了不同的TD,我如何从所选的TD中获得ID我希望更新后的答案将帮助您检查小提琴链接:@marcushis不起作用,但它感觉更接近解决方案,因为您正在使用它,还有其他想法吗?感谢您的帮助您需要将点击输入字段的值填充到roleClicke隐藏字段中,对吗?是的,但我没有点击输入字段。我单击TD,它包含一个输入字段,然后我想将该值填入roleClicked,是的。我确信这段代码应该可以工作,您是否通过ajax加载此表内容?如果是,则需要在“单击”上使用,。。。。方法。我没有使用ajax,也许我以后会在提交数据时使用
$("#roleClicked").text();
$( document ).ready(function() {

            $("#extend td").click(function () {
                $("#roleClicked").val($(this).find("input").val());
            });
    });
$( document ).ready(function() {
    $( "#extend" ).on( "click", "td", function() {
        $("#roleClicked").val($(this).find("input").val());
    });
});