我想要做的就是确保jQuery从每行的输入中获得正确的值。我错过了什么?
function shortDescription() {
$(function() {
var tbl = $(document.getElementById('21.125-mrss-cont-none-content'));
tbl.find('tr').each(function() {
$(this).find("input[name$='6#if']").keypress(function(e) {
if (e.which == 13) {
var input = $(this).val();
$(this).val(input);
console.log(input);
}
});
});
});
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Look in the console.
<table id="21.125-mrss-cont-none-content">
<tr>
<td>
<input type="text" name='6#if' />
</td>
</tr>
</table>
答案 0 :(得分:0)
你可以让它变得更简单
function shortDescription() {
var table = document.getElementById('21.125-mrss-cont-none-content');
$(table).find("input[name$='6#if']").keypress(function( e ) {
if (e.which == 13) {
var input = $(this).val();
$(this).val(input);
console.log(input);
}
});
}
可以在这里测试jsfiddle
答案 1 :(得分:-1)
function shortDescription() {
$(function() {
var tbl = $(document.getElementById('21.125-mrss-cont-none-content'));
tbl.find('tr').each(function() {
$(this).find("input[name$='6#if']").keypress(function(e) {
if (e.which == 13) {
var input = $(this).val();
console.log(input);
$(this).val(input);
}
});
});
});
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Look in the console.
<table id="21.125-mrss-cont-none-content">
<tr>
<td>
<input type="text" name='6#if' />
</td>
</tr>
</table>