如何在顶部的输入字段中访问用户提交的值,并在" LIKE"之后将其放入代码中。在SQL查询中?我的代码使用给定值9999,但我希望该值代替用户输入到输入字段中的任何值。
<!DOCTYPE html>
<html>
<body>
Enter Tracking Code: <input type="text">
<input type="button" value="Submit">
<table id="switch-hitters" class="table table-condensed table-striped"></table>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-sheetrock/1.0.1/dist/sheetrock.min.js"></script>
<script>
var mySpreadsheet = 'https://docs.google.com/spreadsheets/d/1_1elTo5zH1ew6KPYwoWtixX9hzFc8oxdRy5A0LWFkwg/edit#gid=0';
$('#switch-hitters').sheetrock({
url: mySpreadsheet,
query: "select A,B,C,D,E where A like 9999"
});
</script>
</body>
</html>
更新的代码:
<!DOCTYPE html>
<html>
<body>
Enter Tracking Code: <input type="text" id="textbox_id">
<input type="button" value="Submit">
<table id="switch-hitters" class="table table-condensed table-striped"</table>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-sheetrock/1.0.1/dist/sheetrock.min.js"></script>
<script>
var mySpreadsheet = 'https://docs.google.com/spreadsheets/d/1_1elTo5zH1ew6KPYwoWtixX9hzFc8oxdRy5A0LWFkwg/edit#gid=0';
var elem = document.getElementById('textbox_id').value;
$('#switch-hitters').sheetrock({
url: mySpreadsheet,
query: "select A,B,C,D,E where A like "+elem
});
答案 0 :(得分:0)
要从输入文本框中获取值,您可以使用以下内容:
根据您需要在代码中设置的 ID 从文本框中获取价值:
<input type="text" id="textbox_id" >
document.getElementById('textbox_id').value
OR
如果您不想设置ID,请获取HTML文档中第一个文本框的值:
document.getElementsByTagName("input")[0].value;
然后在你的剧本中:
var elem = document.getElementById('textbox_id').value;
$('#switch-hitters').sheetrock({
url: mySpreadsheet,
query: "select A,B,C,D,E where A like "+elem
});