问题
I am new to jQuery world, and only today started using sublime text 2. Therefore, I am not aware of what packages I have to download and how to download. So, I would kindly request if anyone know how do I add jQuery to use it in my sublime text 2 editor. It will be great if you can give me a step by step instructions, like I said I am new to this. Also, how to get list of selections for jQuery.
Any help would be greatly appreciate it. Thanks :]
回答1:
jQuery is a JS library. To use it you need to include it in your document like:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
Than you'll be able to manipulate your DOM elements/events doing crazy stuff like this:
<script>
$(function(){
$('body').prepend('HELLO EVERYONE!');
});
</script>
or like
this demo
To help you in your work Sublime has a possibility to easily include that jQuery library by creating a shortcut snippet, I'll show you how:
Tools > New Snippet...
<snippet>
<content><![CDATA[
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
]]></content>
<tabTrigger>jquery</tabTrigger> <!-- the text that using [Tab] will paste the snippet -->
</snippet>
File > Save As...
(Under Documents And Settings/yourUserName/Application Data/Sublime Text 2/Packages/User/ )
jquery.sublime-snippet
Restart Sublime type jquery
+ hit your TAB key and the jQuery library snippet will be included in your document.
The same way you can create your own snippets that you use over and over for example like
$(function(){
});
var intv = setInterval(function(){
}, 1000 );
回答2:
Sublime Text 2 is just an editor, you don't need to use the packages, snippets, etc. to use jQuery. In the HTML file where you want to use jQuery, you need to add a script tag that points to where the jQuery framework lives (this can either be a local path to where you placed jQuery, or a url of where jQuery resides on the internet).
For example:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
jQuery(function(){
// your code goes here, you can use jQuery at this point
});
</script>
As for a list of "selections" that really depends on the HTML markup you use. At this point, I can only recommend you read the jQuery documentation. Here's a link to their learning center: http://learn.jquery.com/
来源:https://stackoverflow.com/questions/15260945/adding-jquery-to-sublime-text-2