我正在尝试使用replace()函数来调整上面的代码以显示文本:这就是全部吗?同时将文本添加到innerHTML中
<p id="str">Click the button for a surprise.</p>
<form action="#">
<input type="submit" onclick="myFunction()" value="Enter">
</form>
function myFunction(){
document.getElementById('str').innerHTML = "Is this all there is?";
str.replace(str, "Is this all?!")
}
最佳答案
你可以试试这个
<p id="str">Click the button for a surprise.</p>
<form action="#">
<input type="submit" onclick="myFunction()" value="Enter">
</form>
function myFunction(){
var str = document.getElementById('str');
str.innerHTML = "Is this all there is? <moretext>";
str.innerHTML.replace("<moretext>", "Is this all?!");
}