我不熟悉javascript/jquery,有一些基本的東西可以忽略。我想通過調用一個函數來替換一些文本的內容。絕對我嘗試過的每件事都失敗了。用內容替換Div
http://jsfiddle.net/spuder/dTGBy/
HTML
<body>
<div id=test>
</div>
</body>
腳本
$(document).ready(function() {
getTest();
}
function getTest() {
$("#test").html("Hello World");
//$('#test').replaceWith('<h2>New heading</h2>');
//$("#test").attr("text","http://www.w3schools.com/jquery");
//$("#test").attr("href","http://www.w3schools.com/jquery");
//$("#test").html("New text");
//$(".test").html("New text");
//$("test")html.("New text");
//$("test").update("New text");
//document.getElementById("testSpan").innerHTML = "42";
// $("#test").html("<b>Hello world!</b>");
}
//This is supposed to be super easy^
//http://www.w3schools.com/jquery/tryit.asp?filename=tryjquery_dom_html_set
//http://www.w3schools.com/jquery/tryit.asp?filename=tryjquery_dom_attr_set
//http://www.willmaster.com/library/web-development/replace-div-content.php
//http://api.jquery.com/replaceWith/
有缺少一個右括號完成你準備好()調用 - 你在控制檯的Javascript錯誤看? –
爲什麼每行之前都有兩個斜槓! – shnisaka
您鏈接到的jsfiddle不包含jQuery庫,並且您使用的$表達式需要jQuery – Marryat