开发者

.innerHTML from .js file?

开发者 https://www.devze.com 2023-03-03 09:53 出处:网络
i want to p开发者_运维问答rint all text from .js fileto div document.getElementById(\'cart-status\').innerHTML = \"/numberOfcart.js\"

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

精彩评论

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