我有一张表格。
<form id='form1'>
First Name:
<input type="text">
</form>我希望能够找到单词First Name,然后查找以下输入并添加值"Joe“。在name周围可以有标签标签,在输入周围也可以有div/span标签。上面只是一个基本的例子。
我的代码看起来像这样,但当然不能正常工作。谢谢。
$('#form1').text($(this).find('First Name').next().val('Joe')); 发布于 2012-06-27 02:59:47
这不是一个好主意,以这种方式搜索标签将迫使浏览器搜索更多的元素。您应该为文本框使用id,并通过id获取元素。
<label for="firstname">First Name: </label><input id="firstname"/>
$('#firstname').val('joe');或者:
<label for="firstname">First Name: </label><input id="firstname" class="firstname"/>
$('input.firstname').val('joe');或
<label for="firstname">First Name: </label>
<input id="firstname" inputtype="firstname"/>
$('input[inputtype="firstname"]').val('joe');https://stackoverflow.com/questions/11214043
复制相似问题