我有这样的代码需要在href中使用我的Java脚本窗口位置值

时间:2018-11-16 07:50:42

标签: javascript html

        <ul class="sub-menu">
     <li><a href="">Cycle Store & Services</a></li>
     </ul>

        function Demo(anchor) {
            var value = anchor.getAttribute('value')
            var locName=document.getElementById("locName").value;
            if(value.includes('&')){
                value = value.replace("&", "%26");
            }
           if(locName==""){
               alert("Please Select your Location");
           }
            else
                {
                     window.location = "http://www.citycontact.in/SpecificCategory.php?id="+value+"&locName="+locName;
                }
        } 

我有这样的代码,我需要使用“ http://www.citycontact.in/SpecificCategory.php?id=” + value +“&locName =” + locName; href中的值

1 个答案:

答案 0 :(得分:1)

请尝试以下代码。脚本标记任务和变量值缺少“;”分号

 <ul class="sub-menu">
     <li><a href="">Cycle Store & Services</a></li>
     </ul>
<script>
function Demo(anchor) {
            var value = anchor.getAttribute('value');
            var locName=document.getElementById("locName").value;
            if(value.includes('&')){
                value = value.replace("&", "%26");
            }
           if(locName==""){
               alert("Please Select your Location");
           }
            else
                {
                     window.location = "http://www.citycontact.in/SpecificCategory.php?id="+value+"&locName="+locName;
                }
 }

  </script>