[英]How to get the script interacting with a particular HTML element in a web page?
I'm trying to create a customized select drop down menu where suggestions are given when a user enters text in an input box. 我正在尝试创建一个自定义的选择下拉菜单,当用户在输入框中输入文本时会给出建议。
This is the site from where I'm trying to extract the javascript code: http://www.redbus.in/ 这是我尝试从中提取javascript代码的站点: http : //www.redbus.in/
Here's the select drop down working in action: 这是select下拉菜单在起作用:
I tried accessing the event listener for the corresponding input box through dev tools, but was unable to get the relevant script. 我尝试通过开发工具访问相应输入框的事件侦听器,但无法获取相关脚本。
How can I get the corresponding script in this case? 在这种情况下,如何获得相应的脚本? Are there any tricks/specific methods to get the script interacting with a particular HTML element?
是否有任何技巧/特定方法来使脚本与特定的HTML元素进行交互?
PS: I'm a beginner in web development. PS:我是Web开发的初学者。
In Chrome right click the element in the redbus.in page and select "Inspect element" this will bring up dev tools with that element selected. 在Chrome中,右键单击redbus.in页面中的元素,然后选择“检查元素”,这将显示选中该元素的开发工具。
Now under the "Sources" tab go to the "event listeners" 3rd along top-right of dev tools. 现在,在“源”选项卡下,进入开发工具右上角的“事件监听器”第3个位置。 Select the filter icon and choose "selected node only" (see screenshot):
选择过滤器图标,然后选择“仅选定节点”(请参见屏幕截图):
Now look in the "keyup" section and click on the script. 现在,在“ keyup”部分中查找并单击脚本。 Then use the "{}" to beautify the code.
然后使用“ {}”美化代码。
If the minified code is too much to crack. 如果缩小的代码太多,就无法破解。 Then I would suggest using the twitter typeahead jQuery plugin.
然后,我建议使用Twitter预先输入jQuery插件。
You can apply this plugin to any input type="text" on your site like this: 您可以将此插件应用于您网站上的任何输入type =“ text”,如下所示:
$('#the-basics .typeahead').typeahead({
hint: true,
highlight: true,
minLength: 1
},
{
name: 'states',
displayKey: 'value',
source: substringMatcher(states)
});
I have have created a plunk here . 我在这里制造了一颗小东西 。 The code is very easy to implement.
该代码非常易于实现。
I hope this helps :) 我希望这有帮助 :)
IN Chrome DevTools the 3rd panel near 'Computed' is called 'Event Listeners'. 在Chrome DevTools中,“计算”附近的第3个面板称为“事件监听器”。 You can see there all events and sources set on that node: id="txtSource"
您可以看到在该节点上设置的所有事件和源:id =“ txtSource”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.