[英]jquery parent().find(input).val(); accessing two input fields in one table cell on click
I am trying to get values on two input fields (a text field and a select field) inside a table cell with on click button. 我正在尝试通过单击按钮在表格单元格内的两个输入字段(文本字段和选择字段)上获取值。
<td>
<input type="text" onkeypress="return validateNumber(event);" value="'+rate_value+'" class="thinpt" maxlength="3" />
<select class="thinpt1" value="'+format+'">
<option value="21">Seconds</option>
<option value="22">Minutes</option>
<option value="33">Hours</option>
</select>
<button class="setstream" type="button" data-devicevalue="'+device_value+'" data-device="'+device_id+'" data-devicetype="'+device_type+'" data-gateway="'+gateway_id+'">SET</button>
<span class="done grn"></span>
</td>
In jquery am using the below script to get the input from single text field. 在jquery中,使用以下脚本从单个文本字段获取输入。
var threshold = $(this).parent().find('input').val();
I don't know how to get values of two different input box using the above jquery line. 我不知道如何使用上面的jquery行获取两个不同输入框的值。
Any help is appreciated. 任何帮助表示赞赏。
var first = $(this).parent().find('input').val();
var second = $(this).parent().find('select').val();
Its very Easy. 非常简单。 Try This 尝试这个
<td><input type="text" value="'+rate_value+'" class="thinpt" maxlength="3" />
<select class="thinpt1" value"'+format+'" >
<option value="21">Seconds</option>
<option value="22">Minutes</option><option value="33">Hours</option>
</select>
<button class="setstream" type="button" data-devicevalue="'+device_value+'" data-device="'+device_id+'" data-devicetype="'+device_type+'" data-gateway="'+gateway_id+'">SET</button><span class="done grn"></span></td>
Jquery jQuery的
$(function($){
$(".thinpt").on('keyup',function(){
var inputValue=$(this).parent().find('input').val();
var selectValue=$(this).parent().find('select').val();
});
});
Use the same val()
function, create another variable to store your new value: 使用相同的val()
函数,创建另一个变量来存储您的新值:
var thinpt = $('.thinpt').val(); var thinpt1 = $('.thinpt1').val();//get the value of the selected option var thinpt1text = $('.thinpt1 option:selected').text();//get the text of the selected option console.log(thinpt,thinpt1,thinpt1text);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input type="text" onkeypress="return validateNumber(event);" value="x" class="thinpt" maxlength="3" /> <select class="thinpt1" name="format"> <option value="21">Seconds</option> <option value="22">Minutes</option> <option value="33">Hours</option> </select> <button class="setstream" type="button" data-devicevalue="'+device_value+'" data-device="'+device_id+'" data-devicetype="'+device_type+'" data-gateway="'+gateway_id+'">SET</button><span class="done grn"></span>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.