我想将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>
答案 0 :(得分:0)
非常简单:
$.get( "your.txt", function( data ) {
$( ".yourDestinationDivClass" ).html( data );
});
答案 1 :(得分:0)
使用Jquery ajax
,如:
$.ajax({
url : "helloworld.txt",
dataType: "text",
success : function (data) {
$("#destination").html(data);
}
});
答案 2 :(得分:0)
首先,您需要添加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.
}
});