jQuery   发布时间:2022-03-30  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了jquery – 使用children()将值设置为input字段大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我需要使用以下方式设置输入值

<table width="50%" border="0" id="pls-batTing">
    <tr id="1">
        <td>
            <input name="in" type="text" value="5">
        </td>
    </tr>
    <tr id="2">
        <td>
            <input name="in" type="text" value="">
        </td>
    </tr>
</table>

value = $("table#pls-batTing tr:nth-child(1) td:nth-child(1)").children().val();

当我提醒值时,它返回’5′.这很好,也很好.同样,我需要将值设置为第二行的输入字段.我使用以下代码

$("table#pls-batTing tr:nth-child(2) td:nth-child(1)").children().val='test';

但它没有用.有没有办法使用children()方法或使用行ID设置值?

解决方法

试试这个…

$("table#pls-batTing tr:nth-child(2) td:nth-child(1)").children().val('test');

或者你可以尝试其他方式

$("table#pls-batTing tr:eq(1) td:eq(0)").children().val('test');

大佬总结

以上是大佬教程为你收集整理的jquery – 使用children()将值设置为input字段全部内容,希望文章能够帮你解决jquery – 使用children()将值设置为input字段所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。