Javascript Datatables:单击特定按钮时搜索特定字符串

Javascript Datatables:单击特定按钮时搜索特定字符串,javascript,php,jquery,datatables,Javascript,Php,Jquery,Datatables,我的想法是当点击按钮1以获取文本输入并在数据表中进行搜索时 我需要帮助,希望理解 我的代码是这样的,但我没有得到结果。我有其他方法,但我不想刷新页面: <script src="js/ie/jquery.placeholder.js"></script> <script> $(function() { $('input, textarea').placeholder(); }); </script> $(函数(){ $('in

我的想法是当点击按钮1以获取文本输入并在数据表中进行搜索时

我需要帮助,希望理解

我的代码是这样的,但我没有得到结果。我有其他方法,但我不想刷新页面:

<script src="js/ie/jquery.placeholder.js"></script>
<script>
  $(function() {
    $('input, textarea').placeholder();
  });
</script>

$(函数(){
$('input,textarea')。占位符();
});
这样称呼它:

<p class="btn btn-primary" id="myInput" onclick="updateInput('button1')">button1</p>
按钮1


如果我认为您正试图搜索文本区域中的任何值是正确的,那么我下面的示例将帮助您继续

警告的话。。。人们不是读心术的人,你(寻求帮助的人)的更多帮助可以让我们更好地了解你想要实现的目标

如果您正在使用jQuery,正如您在OP中标记的那样

在这里,单击按钮后,jQuery将获得输入字段的.val()

$("#YourButtonIdHere").click(function(){

    // This will get the value of the search input text box 
    var inputText = $("#myInput").val();

    // Now you can do what you wish, Perform an ajax query?
    // More help from you on what you want to do with the value 
    // from the text box once the button has been clicked 
    // will give me a better chance of helping you!
});

由于您在问题中几乎没有提供任何信息,除了您希望在单击按钮时搜索datatable这一事实之外,这应该适合您

var oTable = $("#myTable").DataTable();

$("button1").on('click', function(event){
  var searchText = "button1"; //Specific text that you want to search
  oTable.search(searchText).draw();
}

这里有一个

您的datatables实现在哪里?在寻求解决方案之前,您应该知道如何首先提出问题。。如果你的问题不清楚,我们真的帮不了你。所以你是说,搜索框里有什么文本。。。当您单击按钮时,它将获得搜索框的.val(),并执行datatables查询,对吗?@Birdy是,示例:当您单击按钮1时,它将在该搜索框中搜索:按钮1。就像手工打字一样。谢谢你,但我无法完成。我只想在单击按钮1时在数据表中进行搜索。这就像在搜索框中手动键入:button1。抱歉,希望您能理解。感谢您的回答,但它不起作用,我尝试了以下方法:
button1 var-oTable=$(“#示例”).DataTable()$(“button1”)。在('click',函数(event){var searchText=$(this).val();oTable.search(searchText).draw()}
很抱歉,按钮没有
val
。我会更新我的答案。我找到了方法,但下拉式过滤器无法正常工作。#函数
$(“#acctypqee”)。在('click',函数(){table.column(0).search(this.id.draw();});