最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

xml - Visual Studio Create New Javascript Snippet - Stack Overflow

programmeradmin0浏览0评论

I am fairly new to snippet creation. I have successfully created multiple snippets for C# and HTML. When I ran into troubles I started using the MS Snippet Designer. The trouble I had was when I created a snippet for JS using the following code:

<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="">
  <CodeSnippet Format="1.0.0">
    <Header>
      <SnippetTypes>
        <SnippetType>Expansion</SnippetType>
      </SnippetTypes>
      <Title>tjready</Title>
      <Author>admin</Author>
      <Description>
      </Description>
      <HelpUrl>
      </HelpUrl>
      <Shortcut>$().ready(function() {</Shortcut>
    </Header>
    <Snippet>
      <Code Language="javascript"><![CDATA[$().ready(function() {
//This is a test of the onready
    });]]></Code>
    </Snippet>
  </CodeSnippet>
</CodeSnippets>

My goal is to create the snippet for either JS or CSHTML files. The above does not work in either type of file after an import using the Code Snippet Manager (Tools > CSM). I tried placing the snippet in both the html and JavaScript categories. I also tried modifying the language type of the snippet.

Does anyone see what I am doing wrong?

I am fairly new to snippet creation. I have successfully created multiple snippets for C# and HTML. When I ran into troubles I started using the MS Snippet Designer. The trouble I had was when I created a snippet for JS using the following code:

<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft./VisualStudio/2005/CodeSnippet">
  <CodeSnippet Format="1.0.0">
    <Header>
      <SnippetTypes>
        <SnippetType>Expansion</SnippetType>
      </SnippetTypes>
      <Title>tjready</Title>
      <Author>admin</Author>
      <Description>
      </Description>
      <HelpUrl>
      </HelpUrl>
      <Shortcut>$().ready(function() {</Shortcut>
    </Header>
    <Snippet>
      <Code Language="javascript"><![CDATA[$().ready(function() {
//This is a test of the onready
    });]]></Code>
    </Snippet>
  </CodeSnippet>
</CodeSnippets>

My goal is to create the snippet for either JS or CSHTML files. The above does not work in either type of file after an import using the Code Snippet Manager (Tools > CSM). I tried placing the snippet in both the html and JavaScript categories. I also tried modifying the language type of the snippet.

Does anyone see what I am doing wrong?

Share Improve this question edited Jan 25, 2016 at 19:17 gariepy 3,6846 gold badges23 silver badges34 bronze badges asked Jan 7, 2014 at 21:55 JabberwockyDepilerJabberwockyDepiler 3,4012 gold badges43 silver badges54 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 6

For anyone else that es across this as well, if you need to add a leading $, add two.

<Snippet>
  <Code Language="javascript"><![CDATA[$$().ready(function() {//This is a test of the onready    });]]></Code>
</Snippet>

I found the issue and a solution. The issue was the leading $. Once I took that off I could create the snippit using ctrl K + ctrl X. I wanted to use the shortcut type and auto fill though.

Since I could not get the type and tab auto fill to work I continued to look. I found a Visual Studio jQuery snippet plugin that works for what I am trying to do and es with several snippets ready to go.

The jQuery snippet shortcut on this is jqDocReady or you can use jqDocReadyShort if you do not want the anonymous function in there.

发布评论

评论列表(0)

  1. 暂无评论