我可以在 javascript 的子函数中添加参数吗?
can i add parameters in a child function in javascript?
function smth(txt, a, b, c) {
document.getElementById(txt).innerHTML = a + b + c;
}
function whatever() {
function smth(txt1, "hello ", "my ", "friend");
function smth(txt2, "how ", "are ", "you");
function smth(txt3, "i am ", "good ", "thankyou");
}
is this a thing, (it must be) and how do i get the result if my code is wrong, also sorry about the format of the question i dont know how to ask it.
<button type="button" onclick="whatever()">save</button>
<p id="txt1"></p>
<p id="txt2"></p>
<p id="txt3"></p>
您在 txt1、txt2、txt3 上忘记了撇号 (" "
):
function whatever() {
function smth("txt1", "hello ", "my ", "friend");
function smth("txt2", "how ", "are ", "you");
function smth("txt3", "i am ", "good ", "thankyou");
}
function smth(txt, a, b, c) {
document.getElementById(txt).innerHTML = a + b + c;
}
function whatever() {
smth("txt1", "hello ", "my ", "friend");
smth("txt2", "how ", "are ", "you");
smth("txt3", "i am ", "good ", "thankyou");
}
i had to remove the word "function" from before the smth, and surround the "txt"s with quotations.
function smth(txt, a, b, c) {
document.getElementById(txt).innerHTML = a + b + c;
}
function whatever() {
function smth(txt1, "hello ", "my ", "friend");
function smth(txt2, "how ", "are ", "you");
function smth(txt3, "i am ", "good ", "thankyou");
}
is this a thing, (it must be) and how do i get the result if my code is wrong, also sorry about the format of the question i dont know how to ask it.
<button type="button" onclick="whatever()">save</button>
<p id="txt1"></p>
<p id="txt2"></p>
<p id="txt3"></p>
您在 txt1、txt2、txt3 上忘记了撇号 (" "
):
function whatever() {
function smth("txt1", "hello ", "my ", "friend");
function smth("txt2", "how ", "are ", "you");
function smth("txt3", "i am ", "good ", "thankyou");
}
function smth(txt, a, b, c) {
document.getElementById(txt).innerHTML = a + b + c;
}
function whatever() {
smth("txt1", "hello ", "my ", "friend");
smth("txt2", "how ", "are ", "you");
smth("txt3", "i am ", "good ", "thankyou");
}
i had to remove the word "function" from before the smth, and surround the "txt"s with quotations.