[英]How can I get a html source code of any website using jquery/javascript like php's file_get_content?
[英]How can i show html code and javascript like a string in website
我想將此代碼顯示為網頁中的文本類型。 我正在使用的程序語言是PHP
<div>
<a href="js/index.html">Js</a></div>
<div><a href="php/index.php">PHP</a></div>
<div><a href="test/index.html">Test</a></div>
<input id="in" type="text">
<div class="">Off season <span id="out"></span> this</div>
<script src="js/assets/jquery.js"></script>
<script>
$("#in").keyup(function () {
var text = this.value;
$('#out').text(text);
})
</script>
</div>
HTML轉義
<div>
<a href="js/index.html">Js</a></div>
<div><a href="php/index.php">PHP</a></div>
<div><a href="test/index.html">Test</a></div>
<input id="in" type="text">
<div class="">Off season <span id="out"></span> this</div>
<script src="js/assets/jquery.js"></script>
<pre>
$("#in").keyup(function () {
var text = this.value;
$('#out').text(text);
})
</pre>
</div>
有很多好的答案,但是可以使用的另一個答案是:
<?php
$var = '<div>
<a href="js/index.html">Js</a></div>
<div><a href="php/index.php">PHP</a></div>
<div><a href="test/index.html">Test</a></div>
<input id="in" type="text">
<div class="">Off season <span id="out"></span> this</div>
<script src="js/assets/jquery.js"></script>
<script>
$("#in").keyup(function () {
var text = this.value;
$("#out").text(text);
})
</script>
</div>';
highlight_string($var);
?>
答案是啟發/從這里獲得https://stackoverflow.com/a/28965609/2285345
除了我的評論:
<div>
<a href="js/index.html">Js</a></div>
<div><a href="php/index.php">PHP</a></div>
<div><a href="test/index.html">Test</a></div>
<input id="in" type="text">
<div class="">Off season <span id="out"></span> this</div>
<script src="js/assets/jquery.js"></script>
<pre>
$("#in").keyup(function () {
var text = this.value;
$('#out').text(text);
})
</pre>
</div>
您可以使用w3schools作為起點。
您應該將其包裝在<pre>Your code goes here</pre>
標簽中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.