在javascript中显示链接我做错了什么

时间:2013-06-05 05:36:49

标签: javascript

<script type = "text/javascript">
function DisplayDashboard(Work Package)
{
var Src = '';

if (Work Package=='Google')
{
    Src =<a href="https://www.google.com">Link</a>;
}
else if(Work Package=='Bing') 
{
    Src = <a href ="https://www.bing.com">Link</a>;
}
    return <'+Work Package+'>;
}   
</script>

我要做的是查找Google或Bing,然后在Javascript中显示正确的链接。但由于某种原因,它无法正常工作。

3 个答案:

答案 0 :(得分:1)

  1. 变量名Work Package在字符
  2. 之间不能有空格
  3. string值必须由''""
  4. 包围
  5. 您需要返回Src
  6. 的值

    尝试

    function DisplayDashboard(WorkPackage) {
        var Src = '';
    
        if (WorkPackage == 'Google') {
            Src = '<a href="https://www.google.com">Link</a>';
        } else if (WorkPackage == 'Bing') {
            Src = '<a href ="https://www.bing.com">Link</a>';
        }
        return Src;
    }
    

答案 1 :(得分:0)

Work Package替换为WorkPackage。删除空格。

function DisplayDashboard(WorkPackage)
{
var Src = '';

if (WorkPackage=='Google') 
    Src ='<a href="https://www.google.com">Link</a>';   
else if(WorkPackage=='Bing')    
    Src = '<a href ="https://www.bing.com">Link</a>';   
    return src;
}   

答案 2 :(得分:0)

我猜你需要用双引号括起HTML来形成一个有效的字符串吗?

如:

Src = "<a href="https://www.google.com">Link</a>";