[英]How to load a txt file into div tab using Jquery
我想將txt文件加載到div tab-content
。 在下面的代碼中,我在tab-content
內使用了一個段落。 我要顯示該文本文件的信息,而不是該段落。 如何使用jquery做到這一點?
<div class="create">
<ul class="nav nav-tabs" id="myTab" style="width: 22%">
<li class="active"><a href="#cpp">C++</a></li>
<li><a href="#java">Java</a></li>
<li><a href="#python">Python</a></li>
</ul>
<div class="tab-content">
<div id="cpp" class="tab-pane fade in active">
<h3>#Creating an array in C++</h3>
</div>
<div id="java" class="tab-pane fade">
<h3>#Creating an array in Java</h3>
</div>
<div id="python" class="tab-pane fade">
<h3>#Creating an array in Python</h3>
</div>
</div>
</div>
<!--#End of create div-->
<div class="insert">
<ul class="nav nav-tabs" id="myTab2" style="width: 22%">
<li class="active"><a href="#myTab2-cpp">C++</a></li>
<li><a href="#myTab2-java">Java</a></li>
<li><a href="#myTab2-python">Python</a></li>
</ul>
<div class="tab-content">
<div id="myTab2-cpp" class="tab-pane fade in active">
<h3>#Inserting an array in C++</h3>
</div>
<div id="myTab2-java" class="tab-pane fade">
<h3>#Inserting an array in Java</h3>
</div>
<div id="myTab2-python" class="tab-pane fade">
<h3>#Inserting an array in Python</h3>
</div>
</div>
</div>
相當容易:
$.get( "your.txt", function( data ) {
$( ".yourDestinationDivClass" ).html( data );
});
像這樣使用Jquery ajax
:
$.ajax({
url : "helloworld.txt",
dataType: "text",
success : function (data) {
$("#destination").html(data);
}
});
首先,您需要添加jQuery ajax
,然后需要在該Ajax請求中添加dataType
選項。 請遵循以下代碼::
$.ajax({
url : "helloworld.txt", // your txt file path
dataType: "text",
success : function (data) {
$(".tab-content").html(data); // replace .tab-content if you want to put .txt file's data in other place.
}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.