[英]What's wrong with this JQuery?
当我做
$(document).ready(function(){
$('form').live('submit', function(){
$('#template').tmpl([{ "id" : "555" }, { "in" : "checked" } ]).prependTo('#content');
});
});
带有和带有 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>
然后 Firefox 中的错误控制台说jquery.tmpl.min.js
的第 1 行中的语法错误来自JQuery.tmpl()
JSFiddle 在
是吗
$('#template').tmpl([{ "id" : "555" }, { "in" : "checked" } ]).prependTo('#content');
那是错的?
更新更新的 JSFiddle 并发布失败的代码。
我在您的 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>
和你的 JavaScript:
$(document).ready(function(){
$('form').live('submit', function(){
$('#template').tmpl({ "Id" : "555","In" : "checked" }).prependTo('#content');
return false;
});
});
它现在对我有用。
我认为的问题是模板变量名称,我将它们大写,模板数据是 2 个对象的数组,而不是简单的 object。 (还稍微更改了模板脚本 MIME。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.