Javascript:<;脚本src=jquery…仅当条件为true时
我正在用javascript开发,只想在条件得到验证的情况下插入脚本 例如:Javascript:<;脚本src=jquery…仅当条件为true时,javascript,jquery,get,conditional-statements,Javascript,Jquery,Get,Conditional Statements,我正在用javascript开发,只想在条件得到验证的情况下插入脚本 例如: var a = exampleVariable; if (a == conditionIwant) { // append to head: <script src="http://code.jquery.com/jquery-1.5.js"> </ script> }; //or something like this var a=example变量; if(a==co
var a = exampleVariable;
if (a == conditionIwant) {
// append to head:
<script src="http://code.jquery.com/jquery-1.5.js"> </ script>
}; //or something like this
var a=example变量;
if(a==conditionIwant){
//附加到标题:
}; //或者类似的事情
如果条件为真,我如何才能插入jquery.js?这非常简单:
if(somethingIsTrue) {
var sc = document.createElement('script');
sc.src = 'http://code.jquery.com/jquery-1.5.js';
sc.type = 'text/javascript';
if(typeof sc['async'] !== 'undefined') {
sc.async = true;
}
document.getElementsByTagName('head')[0].appendChild(sc);
}
您是否可以访问其他技术—PHP、ASP等。如果可能,这确实是您应该在服务器端执行的操作。最终您可以添加
sc.async=true代码>如果不想阻止并行下载。