开发者

What's wrong with this JQuery?

When I do

$(document).ready(function(){
   $('form').live('submit', function(){
      $('#template').tmpl([{ "id" : "555" }, { "in" : "checked" }   ]).prependTo('#content');
   });
});

with and with HTML

<!DOCTYPE html>
<html dir="ltr">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

    <script src="http://code.jquery.com/jquery-1.6.1.min.js"></script>
    <script src="http://jqueryui.com/ui/jquery.ui.core.js"></script>
        <script src="http://jqueryui.com/ui/jquery.ui.widget.js"></script>
    <script src="http://jqueryui.com/ui/jquery.ui.datepicker.js"></script>
    <script src="http://ajax.microsoft.com/ajax/jquery.templates/beta1/jquery.tmpl.min.js"></script>

    <script type="text-x-jquery/template" id="template"> 
      <form action="" method="post">
      "${id}" <div class="cellData cellRadios"> <input name="ctype" value="individuel" type="radio" "${in}"/> </div>
      </form>
    </script>

  </head>
  <body>

  <form action="" method="post">
  <input value="Save" type="submit">
  </form>

  <br><br>

  <div id="content"> </div>

then Error Console in Firefox says Syntax Error in line 1 of jquery.tmpl.min.js which is from JQuery.tmpl()

JSFiddle at

http://jsfiddle.net/Cu5Mj/4/

Is it

$('#template').tmpl([{ "id" : "555" }, { "in" : "checked" }   ]).prependTo('#content')开发者_StackOverflow中文版;

that is wrong?

Update Updated JSFiddle and post with code that fails.


I changed the followings in your HTML:

<script type="text/x-jquery-tmpl" id="template">
    <form action="" method="post">
        "${Id}" <div class="cellData cellRadios"> <input name="ctype" value="individuel" type="radio" ${In} /> </div>
    </form>
</script>

and your JavaScript:

$(document).ready(function(){
   $('form').live('submit', function(){
      $('#template').tmpl({ "Id" : "555","In" : "checked" }).prependTo('#content');
       return false;
   });
});

and it works for me now.

The problems I think was the template variable names, I capitalized them, and the template data was an array of 2 objects instead of a simple object. (Also changed the template script MIME a bit.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜