简体   繁体   English

在锚标签中动态传递 href

[英]dynamically passing href in anchor tag

i want to redirect user to registration based on there role.我想根据那里的角色将用户重定向到注册。 like there is two roles user and shop if user select user role then it will be directed to the ragic.php(registration customer) if selected shop then ragis.php Hear is the code...就像有两个角色用户和商店如果用户 select 用户角色那么它将被定向到 ragic.php(注册客户)如果选择商店然后 ragis.php 听到是代码......

 Link: `<td colspan=3 align="center"><font size=6 ><a onclick="return check_role()" href="" id="ref" name="Ragistration">Ragistration</a>`

Selecting Role: 

<select id="role" name="role">
                        <option value="ragic.php">user</option>
                        <option value="shop/ragis.php">shop</option>
                    </select>
Java Script Function :

 function check_role()
            {
                    var r=document.getElementById('role').value;
                    alert(r);
                    document.getElementById("ref").value = test;                    
            }
                

one problem is how i pass a javascript variable into anchor href.一个问题是我如何将 javascript 变量传递给锚 href。 or i also try for php hear is code或者我也尝试 php 听到是代码

  if(@isset($Ragistration))
{
    if(@$role=="shop")
    $r="shop/ragis.php";
elseif(@$role=="user")
    $r="ragic.php";

}

and for php anchor tag will be <a href="<?php echo $r?>" ></a>对于 php 锚标记将是<a href="<?php echo $r?>" ></a>

Update your JavaScript function like this:像这样更新您的 JavaScript function:

function check_role()
{
  var r=document.getElementById('role').value;
  alert(r);
  location.href = r;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM