如何为jQuery创建代码段?

时间:2018-07-09 13:58:45

标签: javascript code-snippets sublimetext-snippet

所以我想为以下内容创建一个代码段:

$("input").click(function(event){
    //code goes here
});

但是,当我尝试以崇高的文字形式创建代码段时:

<snippet>
    <content><![CDATA[
$("${1:Tag}").click(function(event)
{
    ${2:code goes here}
});
]]></content>
    <!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
    <tabTrigger>sclick</tabTrigger>
    <!-- Optional: Set a scope to limit where the snippet will trigger -->
    <scope>source.js</scope>
</snippet>

显然,两者的“ $”之间存在某种冲突。 我通读了文档,但没有找到任何东西。 如何为此创建一个代码段?

1 个答案:

答案 0 :(得分:2)

使用\转义$

<snippet>
    <content><![CDATA[
\$("${1:Tag}").click(function(event)
{
    ${2:code goes here}
});
]]></content>
    <!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
    <tabTrigger>sclick</tabTrigger>
    <!-- Optional: Set a scope to limit where the snippet will trigger -->
    <scope>source.js</scope>
</snippet>

the only supported escape sequence。)

相关问题