简体   繁体   English

jQuery数据表,sDom自定义工具栏无法选择输入字段

[英]Jquery Datatables, sDom custom toolbar can't select input field

I was successful in adding a custom toolbar to the sDom. 我成功地向sDom添加了自定义工具栏。 I have two input textboxes, and a button. 我有两个输入文本框和一个按钮。 I can create a click event on the button via Jquery, but the two textboxes are not responding to Jquery selectors using their ID or class names, I want to wire a Jquery event to one of the textboxes. 我可以通过Jquery在按钮上创建click事件,但是两个文本框未使用其ID或类名响应Jquery选择器,我想将Jquery事件连接到其中一个文本框。

I can easily access the two input boxes using CSS (ie: .typeahead1{ display: none; }. 我可以使用CSS轻松访问两个输入框(即:.typeahead1 {display:none;}。

When I inspect the element (input textbox) via the browser developer tools, the class name and id are displayed that I'm using to select the elements with Jquery. 当我通过浏览器开发人员工具检查元素(输入文本框)时,将显示要用于通过Jquery选择元素的类名和ID。

To test my Jquery selection I tried to hide the elements in the sDom. 为了测试我的Jquery选择,我试图隐藏sDom中的元素。 I can easily hide the standard datatables search filter using ($('.dataTables_filter, .dataTables_info').hide(); 我可以使用($('。dataTables_filter,.dataTables_info')。hide();轻松隐藏标准数据表搜索过滤器。

I can not hide the individual input textboxes contained in the custom toolbar. 我无法隐藏自定义工具栏中包含的各个输入文本框。 I can hide the whole custom toolbar, but not the individual controls. 我可以隐藏整个自定义工具栏,但不能隐藏单个控件。

I used this to inject the custom toolbar into the sDom (ie: sDom: '<"H"<"toolbar">f>t<"F"ip>',). 我用它来将自定义工具栏注入sDom(即:sDom:'<“ H” <“ toolbar”> f> t <“ F” ip>',)。

How can I select a single item (input id="City1") in my custom toolbar using Jquery when it is inside the sDom? 当它位于sDom内时,如何使用Jquery在自定义工具栏中选择单个项目(输入id =“ City1”)?

I'm sure this is a Jquery selector syntax I'm just not getting right. 我确定这是一个Jquery选择器语法,我只是不太正确。

Here is the custom toolbar I'm injecting into the sDom: $("div.toolbar").html('<div class="toolbarCustom">City, State &nbsp;<input id="City1" class="typeahead1" type="text" size="40" placeholder="City and State separated by comma" autocomplete="off" />&nbsp;&nbsp;Zip <input id="ZipCode1" placeholder="Zipcode" type="text" size="10" />&nbsp;&nbsp; <button id="btnSetLocation" type="button" class="btn btn-primary">Set Location</button></div>'); 这是我要注入sDom的自定义工具栏: $("div.toolbar").html('<div class="toolbarCustom">City, State &nbsp;<input id="City1" class="typeahead1" type="text" size="40" placeholder="City and State separated by comma" autocomplete="off" />&nbsp;&nbsp;Zip <input id="ZipCode1" placeholder="Zipcode" type="text" size="10" />&nbsp;&nbsp; <button id="btnSetLocation" type="button" class="btn btn-primary">Set Location</button></div>');

Any help would be greatly appreciated. 任何帮助将不胜感激。

Thank you Bill 谢谢比尔

After much research and sheer frustration, I was able to get my control working. 经过大量的研究和无奈的挫败,我得以使我的控制工作。

The main issue was that the div containing the controls was being dynamically created, after I hard coded the html into the form, Jquery was able to easily recognize the id and class name. 主要问题是包含控件的div是动态创建的,在将html硬编码为表单之后,Jquery能够轻松识别id和类名。

I did not realize that Jquery binds only the elements that exist at the time of binding. 我没有意识到Jquery只绑定绑定时存在的元素。

I could have gotten away with a late binding with $(document).on..., but I could not match it up with the bootstrap typeahead addon I wanted to use. 我本可以使用$(document).on ...进行后期绑定,但是我无法将其与我想使用的bootstrap typeahead插件相匹配。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM