如何使用字符串函数运行此代码

时间:2017-12-28 19:32:10

标签: javascript html

我试图为此获得结果:

function getAttackString() {
var foo = "d3294hb34";
var bar = "x338p5ij8";
return "The code is: "+(foo.substr(3,foo.length-6))+(bar.substr(2));
}    

并尝试通过在HTML

上运行以下脚本来实现此目的
<p id="demo"></p>   

function getAttackString(a, b) {
    return (a.substr(3,a.length-6))+(b.substr(2));
}

document.getElementById("demo").innerHTML = getAttackString(d3294hb34, x338p5ij8);

但它似乎不起作用。谁能发现我做错了什么?提前致谢

1 个答案:

答案 0 :(得分:2)

document.getElementById("demo").innerHTML = getAttackString(d3294hb34, x338p5ij8);

应该是

document.getElementById("demo").innerHTML = getAttackString("d3294hb34", "x338p5ij8");