开发者

.innerHTML from .js file?

i want to p开发者_运维问答rint all text from .js file to div

document.getElementById('cart-status').innerHTML = "/numberOfcart.js" 


You could use jQuery to do something like this:

$.get('/numberOfcart.js', function(data) {
  $('#cart-status').text(data);
}

but you are simply loading in the .js file, not running it.


Directly displaying the the contents of js file by JavaScript is not possible (or I don`t know, if somebody knows a way - welcome). So by PHP:

$file = file_get_contents( 'script.js' );
echo "<pre>" . htmlentities ( $file ) . "</pre>";

With an ajax callback to the php script, set to the div.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜