不,不要这样做.
......好吧,有一种方法,但不要反正...
这里是....
function loadScriptWithReplacements(url) {
try {
var rq = null;
if(window.XMLHttpRequest)
rq = new XMLHttpRequest();
else if(window.ActiveXObject) {
try {
rq = new ActiveXObject("Msxml2.XMLHTTP");
} catch(o) {
rq = new ActiveXObject("Microsoft.XMLHTTP");
}
}
rq.open("GET", url, false);
rq.send(null);
document.write('<script>' + rq.responseText.replace(/(and|or|\<\>)/g, function(r) {
return {
'and': '&&',
'or' : '||',
'<>' : '!=='
}[r];
}) + '</script>');
} catch(ex) {
// We can't have a fallback because you're using invalid JavaScript :(
throw new Error("Could not use Ajax.");
}
}
Run Code Online (Sandbox Code Playgroud)
但是,不要那样做!您也可以在服务器端执行替换,但不要这样做!
在服务器端执行此操作会增加服务器的压力,只需记住如何正确编写JavaScript即可避免执行某些操作.