I want to do something like this:
$("#startButton").click(function() {
<?php if(somecondition){ ?>
<script src="some-external-js-srouce"></script>
<noscript><img src="irrelevant"></noscript>
<?php } ?>
});
Meaning that I want to execute some external javascript inside a jquery function if a button has been clicked. Can you help me?
You're putting HTML inside JavaScript. That's not quite possible.
You probably want $.getScript
to load and execute a script dynamically at runtime. It does not support <noscript>
but you're using JavaScript for it anyway, so that does not really make sense to me...
if you want to execute a javascript function from an external file then you can try like this -
<script type="text/javascript" src="myjs.js">
// code that will refer functions of myjs.js
</script>
use jQuery.getScript( url, function(){});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.