简体   繁体   English

Netbeans JQuery Selector自动完成

[英]Netbeans JQuery Selector auto-complete

I can't get Netbeans to auto-complete my selectors for JQuery, example: 我不能让Netbeans自动完成我的JQuery选择器,例如:

<a id="hello" href="#">Hello</a>
<script type="text/javascript">
    $("|").hide();
</script>

As far as i understand the documentation at this point it should show the tags available on the page when i press control+space at the | 据我所知,此时的文档应该显示当我按下控制+空格时页面上可用的标签 position, but instead displays no suggestions. 位置,但不显示任何建议。 Links [1] and [2] shows clearly that this has been implemented. 链接[1]和[2]清楚地表明这已经实施。 I have not tried prototype, link [2] shows that JQuery support has been added as well. 我没有尝试过原型,链接[2]表明JQuery支持也已添加。

The auto-complete of functions works perfectly, with the embedded library of JQuery 1.4.2, it is only the selector auto-complete that does not work. 函数的自动完成工作完美,使用JQuery 1.4.2的嵌入式库,只有选择器自动完成才能工作。 Any suggestions? 有什么建议?

[1] http://wiki.netbeans.org/JavaScript#Embedded_Completion [1] http://wiki.netbeans.org/JavaScript#Embedded_Completion

[2] http://wiki.netbeans.org/JavaScript#Recently_Added [2] http://wiki.netbeans.org/JavaScript#Recently_Added

Product Version: NetBeans IDE 6.8 (Build 200912041610)
Java: 1.6.0_18; Java HotSpot(TM) Client VM 16.0-b13
System: Windows XP version 5.1 running on x86; Cp1252; en_US (nb)

5 years later update: 5年后更新:

As of at least version 8.0.2 Netbeans now properly auto-completes jQuery selectors in both php and html pages. 至少从版本8.0.2开始,Netbeans现在可以在php和html页面中正确地自动完成jQuery选择器。 I am unsure if this is due to some other changes on the editor engine or they finally caught the discrepancy but either way it works now, yay! 我不确定这是否是由于编辑器引擎上的其他一些变化,或者他们最终发现了差异,但无论哪种方式现在都可以使用,耶!

Link 1 says that there is code completion on element ids that appear in the html itself. 链接1表示在html本身中出现的元素ID上有代码完成。 They also say that it works with Prototype.js. 他们还说它适用于Prototype.js。 I believe that it would work for jquery too, but don't forget - in order to select an element using it id in jquery you do $('#id') - with #. 我相信它也可以用于jquery,但是不要忘记 - 为了在jquery中选择一个使用它的元素你用$('#id') - #。

What they meant in their example if you have $("f|") is that if you start writing $("f and the cursor of typing is after the f (they put "|" in order to mark the cursor), then code completion should show all relevant elements. if you have $("f|") ,他们在他们的例子中的意思是,如果你开始写$("f并且键入的光标在f之后(他们将”|“设置为标记光标),那么代码完成应显示所有相关元素。

Try that: 试试看:
in html: <div id="blabla">12345</div> 在html中: <div id="blabla">12345</div>
in jscript: $('bl'); 在jscript中: $('bl');
after the bl press control+space, and I believe that it will display to you blabla. 在bl按下控制+空间后,我相信它会显示给你blabla。

Naor answer made me rethink what I was doing, but it didn't quite answer my question. Naor的回答让我重新思考我在做什么,但它并没有完全回答我的问题。 So let me provide the solution I found in case anyone is interested. 所以,让我提供我发现的解决方案,以防任何人感兴趣。

When working with netbeans, the auto-complete function behaves differently between php files and html. 使用netbeans时,自动完成功能在php文件和html之间表现不同。 In html jquery selectors auto-completes as expected. 在html jquery选择器中按预期自动完成。 But when trying to do the same within a php file in an html section of code, it will fail to auto-complete. 但是当试图在代码的html部分中的php文件中执行相同操作时,它将无法自动完成。

Just make sure that if you are expecting this feature to work, that you are using html files, not php. 只要确保如果您希望此功能正常工作,那么您使用的是html文件,而不是php。 I will submit this as a feature/bug to the netbeans guys, hopefully they can fix it and make html/js auto-completion available to all file types that can include html/js code. 我会将此作为功能/错误提交给netbeans人,希望他们可以修复它并使html / js自动完成可用于所有可包含html / js代码的文件类型。

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

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