jquery - 如何使用jQuery显示标签和输入值?

标签 jquery input label

我需要一个 jQuery 函数来遍历具有以下结构的段落:

<p>
  <label>some label</label>
  <input type="text" value=""/>
</p>

该函数应使用标签文本作为输入值。

谢谢!

最佳答案

$('p > label + input').val(function() { return $(this).prev().text(); });

示例: http://jsfiddle.net/D392c/

关于jquery - 如何使用jQuery显示标签和输入值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4028929/

相关文章:

javascript - Jquery 未捕获类型错误 : Cannot read property 'replace' of undefined

javascript - 有没有办法在运行时从源代码中隐藏一个div

python - 如何让 PySimpleGui 读取我的输入并更新我的窗口?

javascript - vs code .value 不被 intellisense 识别

javascript - jQuery fadeIn/Out - 从所选元素中删除动画

javascript - 获取由 javascript 读取的数组文本字段值

html - 星级 "Turned Around"- HTML、CSS

c - 结构标签

javascript - 通过两个标签小部件作为下拉菜单在博客平台中搜索

javascript - Bootstrap/jQuery 单选按钮在 Firefox/Safari 上不起作用