getQueryVariable问题和问题

时间:2015-02-02 17:43:30

标签: javascript

这个脚本困扰着我,无论我做什么,它都显示顶级document.write行是错误的。它在那时失败了。我希望有人可以帮助我 头     

function getQueryVariable(variable)
{
   var query = window.location.search.substring(1);
   var vars = query.split("&");
   for (var i=0;i<vars.length;i++) {
           var pair = vars[i].split("=");
           if(pair[0] == variable){return pair[1];}
   }
   return(false);
}
</script>

<script type='text/javascript'>
<!--

if (getQueryVariable("catid")= "Merchandise") {
document.write('<div id='div-gpt-ad-1403912225717-2'><script type='text/javascript'>googletag.cmd.push(function() { googletag.display('div-gpt-ad-1403912225717-2'); });</script></div>')
document.write('<div id='div-gpt-ad-1403912225717-2'><script type='text/javascript'>googletag.cmd.push(function() { googletag.display('div-gpt-ad-1403912225717-3'); });</script></div>')
} else if (getQueryVariable("catid")= "Automotive") {
document.write('<div id='div-gpt-ad-1403912225717-2'><script type='text/javascript'>googletag.cmd.push(function() { googletag.display('div-gpt-ad-1403910107020-2'); });</script></div>')
document.write('<div id='div-gpt-ad-1403912225717-2'><script type='text/javascript'>googletag.cmd.push(function() { googletag.display('div-gpt-ad-1403910107020-3'); });</script></div>')
} else if (getQueryVariable("catid")= "Yard Sales") 
document.write('<div id='div-gpt-ad-1403912225717-2'><script type='text/javascript'>googletag.cmd.push(function() { googletag.display('div-gpt-ad-1403912225717-2'); });</script></div>')
document.write('<div id='div-gpt-ad-1403912225717-2'><script type='text/javascript'>googletag.cmd.push(function() { googletag.display('div-gpt-ad-1403912225717-3'); });</script></div>')
} else if (getQueryVariable("catid")= "Public Notices") {
document.write('<div id='div-gpt-ad-1403912225717-2'><script type='text/javascript'>googletag.cmd.push(function() { googletag.display('div-gpt-ad-1403910107020-2'); });</script></div>')
document.write('<div id='div-gpt-ad-1403912225717-2'><script type='text/javascript'>googletag.cmd.push(function() { googletag.display('div-gpt-ad-1403910107020-3'); });</script></div>')
} else if (getQueryVariable("catid")= "Services") {
document.write('<div id='div-gpt-ad-1403912225717-2'><script type='text/javascript'>googletag.cmd.push(function() { googletag.display('div-gpt-ad-1403910107020-2'); });</script></div>')
document.write('<div id='div-gpt-ad-1403912225717-2'><script type='text/javascript'>googletag.cmd.push(function() { googletag.display('div-gpt-ad-1403910107020-3'); });</script></div>')
} else if (getQueryVariable("catid")= "Real Estate for Sale") {
document.write('<div id='div-gpt-ad-1403912225717-2'><script type='text/javascript'>googletag.cmd.push(function() { googletag.display('div-gpt-ad-1403913003830-2'); });</script></div>')
document.write('<div id='div-gpt-ad-1403912225717-2'><script type='text/javascript'>googletag.cmd.push(function() { googletag.display('div-gpt-ad-1403913003830-3'); });</script></div>')
} else {
document.write('<div id='div-gpt-ad-1403912225717-2'><script type='text/javascript'>googletag.cmd.push(function() { googletag.display('div-gpt-ad-1403911366201-2'); });</script></div>')
document.write('<div id='div-gpt-ad-1403912225717-2'><script type='text/javascript'>googletag.cmd.push(function() { googletag.display('div-gpt-ad-1403911366201-3'); });</script></div>')
}
//-->
</script>

1 个答案:

答案 0 :(得分:0)

正确使用字符串组合(在单引号内使用双引号):

document.write('<div id="div-gpt-ad-1403912225717-2"><script type="text/javascript">googletag.cmd.push(function() { googletag.display("div-gpt-ad-1403912225717-2"); });</script></div>')