包括一个脚本的使用javascript只有一小部分
问题描述:
是有办法,我只能包含一个这样的脚本的一小部分:包括一个脚本的使用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?
感谢
答
我想你想的就是怎样得到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>
使用jquery.fn.html方法$( '.Hellwold')。HTML() –