在锚标签中动态传递 href

dynamically passing href in anchor tag

我想根据角色将用户重定向到注册。就像有两个角色 user 和 shop if user select user role then it will be directed to the ragic.php(registration customer) if selected shop then 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;                    
            }
                

一个问题是我如何将 javascript 变量传递给锚 href。或者我也尝试 php 听说是代码

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

}

并且对于 php 锚标记将是 <a href="<?php echo $r?>" ></a>

像这样更新您的 JavaScript 函数:

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