我想使用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