Php 如何从列表中获取一个输入字段的数据值?
如何从列表中获取第一个输入字段的值Php 如何从列表中获取一个输入字段的数据值?,php,jquery,Php,Jquery,如何从列表中获取第一个输入字段的值 <button id="hello">get data</button><br><br> <table> <td><label for="voucher_<?php echo $counter; ?>">D/N Number <?php echo $counter; ?></label><br> <input
<button id="hello">get data</button><br><br>
<table> <td><label for="voucher_<?php echo $counter; ?>">D/N Number <?php echo $counter; ?></label><br>
<input type="text" name="voucher_<?php echo $counter; ?>" class="input-field exsmall-input" value="<?php echo $voucher; ?>" placeholder="D/N Number" id="voucher_<?php echo $counter; ?>" required>
</td></table>
当我运行此javascript时,会得到未定义的值。您可以按如下方式执行:-
$(document).ready(function(){
$('#hello').click(function(){
var name = $("div[id^='voucher']:visible:first").val();
alert(name);
});
});
或:-
出现错误的原因是使用了错误的选择器以输入元素为目标。输入元素没有id凭证。您需要输入ID以使现有代码正常工作 或者,您可以在此处从当前HTML使用以选择器开头的属性:
$('#hello').click(function(){
var name = $("input[name^='voucher_']").val();
alert(name);
});
试试这个:-
$(document).ready(function() {
$('#hello').click(function() {
var name = $('table').find('input[type=text]').filter(':visible:first')
.val();
});
});
$('#hello').click(function(){
var name = $("input[name^='voucher_']").val();
alert(name);
});
$(document).ready(function() {
$('#hello').click(function() {
var name = $('table').find('input[type=text]').filter(':visible:first')
.val();
});
});