我想使用jQuery生成一些HTML,我想只创建具有所需的类等元素,然后将它们附加到对方,如果这是有道理的。我写了下面的代码,它不会产生任何错误,但也不会将HTML添加到容器中。使用jQuery生成HTML
怎么了?
(function($) {
$.fn.twitter_plugin = function(options) {
var container = this[0];
console.log('Started');
// Make aJax call
// Generate HTML
$con = $("<div>", { "class" : "tweet" });
$(container).append($con);
$col1 = $("<div>", { "class" : "twocol" });
$con.append($col1);
$col2 = $("<div>", { "class" : "tencol last" });
$con.append($col2);
// Profile Image
$tweet_profile_div = $("<div>", { "class" : "tweet-profile-photo" });
$col1.append($tweet_profile_div);
$profile_img = $("img", { "src" : '', "class" : "responsive-img" });
$tweet_profile_div.append($profile_img);
// END Profile Image
// Tweet
$tweet_head = $("div", { "class" : "tweet-head" });
// END Tweet
};
}(jQuery));
执行此像这样:
<script src="js-src/themev2/twitter_plugin.js"></script>
<script>
$(document).ready(function() {
$("#map_canvas").twitter_plugin({ });
});
</script>
编辑1
@Sean默,如显示的console.log被没有你认为改变执行我的twitter_plugin功能, ,所以这不是问题
你得到你的控制台日志? – Adjit
你有没有包含jQuery? – gaetanoM