我想使用td id找到最高价值和左值,但我必须采用文本框值,我必须发送给我找到帮助我。
string[] imageTypes = {"jpg", "jpeg","bmp","gif", "png"};
string filename = "abc.jpg";
Boolean validFileName = imageTypes.Contains(filename.Substring(filename.LastIndexOf(".") + 1).ToLower());
答案 0 :(得分:1)
假设t2
是你的文本框,你会想要这样的东西:
var td = $('#' + $('#t2').val());
这样做是将文本框的值附加到'#'字符,然后将此连接字符串作为选择器传递给jQuery。
使用上面的符号:
$(document).ready(function() {
$("#button").click(function() {
var inputtedID = $("#t2").val();
if (inputtedID) {
//check that it is not an empty string
var td = $("#" + inputtedID);
if (td.length > 0) {
//if there is a td with that ID
var offset = td.offset();
$("#result").text("The offset for " + inputtedID + ": {top: " + offset.top + ", left: " + offset.left + "}");
} else {
$("#result").text("There is no element with id of " + inputtedID);
}
}
});
});
td{
min-width: 10px;
min-height: 10px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
<tr>
<td>5</td>
<td class="d" id="A5"></td>
<td class="w" id="B5"></td>
<td class="d" id="C5"></td>
<td class="w" id="D5"></td>
<td class="d" id="E5"></td>
<td class="w" id="F5"></td>
<td class="d" id="G5"></td>
<td class="w" id="H5"></td>
</tr>
</table>
<input id="t2" />
<button id="button">Get Offset</button>
<br>
<span id="result"></span>