2017-03-18 54 views
0

是有辦法,我只能包含一個這樣的腳本的一小部分:包括一個腳本的使用javascript只有一小部分

<?php 
$url = 'https://www.example.com'; 
$content = file_get_contents($url); 
$first_step = explode('<div class="HelloWorld">' , $content); 
$second_step = explode('</div class="HelloWorld">' , $first_step[1]); 

echo $second_step[0]; 

...但是,僅僅使用Javascript,而不是PHP?

感謝

+0

使用jquery.fn.html方法$( '.Hellwold')。HTML() –

回答

0

我想你想的就是怎樣得到DIV helloworld.using jquery.fn.html代替的innerHTML什麼。

console.log($(".HelloWorld").html());
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<div class="HelloWorld"><span>foo</span>bar</div>

或者您也可以使用DOM API,其直接HTML元素有一個innerHTML屬性做到這一點:

console.log(document.querySelector(".HelloWorld").innerHTML);
<div class="HelloWorld"><span>foo</span>bar</div>

相關問題