0
<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>

我想做的是寻找谷歌或必应,然后在 Javascript 中显示正确的链接。但由于某种原因,它不起作用。

4

3 回答 3

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

尝试

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;
}
于 2013-06-05T05:38:32.567 回答
0

替换Work PackageWorkPackage.Remove 空格。

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;
}   
于 2013-06-05T05:39:08.170 回答
0

我猜您需要将 HTML 用双引号括起来以形成有效的字符串?

如:

Src = "<a href="https://www.google.com">Link</a>";
于 2013-06-05T05:39:59.190 回答