这可能吗?如果是这样,怎么样?¨是否可以使用变量作为参数setAttribute onclick = myFunction()?
var variableCross = localStorage.getItem('cross'+localStorage.getItem('number'));
del.setAttribute("onClick","myFunction(variableCross);");
Run Code Online (Sandbox Code Playgroud)
myFunction的(variableCross); 像字符串一样发送变量?不是吗?
谢谢
假设您有一个矩形,width=10, height=20并且想要获取周长中每个像素的坐标。你可以用 4 个 for 循环来完成它,但没有更好、更简洁的方法吗?
for(x=0; x<width; x++){
doSomethingWith(x,0)
}
for(y=0; y<height; y++){
doSomethingWith(0,y)
}
for(x=1; x<width; x++){
doSomethingWith(x,height)
}
for(y=1; y<height; y++){
doSomethingWith(width,y)
}
Run Code Online (Sandbox Code Playgroud)
我将使用 javascript,但对伪代码或其他语言的帮助表示赞赏。
嘿,我想要一个可以拆分字符串的函数,例如"(12/x+3)*heyo",我可以自己编辑每个数字、字母和单词,然后返回编辑后的版本。到目前为止,我得到了这个(它没有按预期工作):
function calculate(input){
var vars = input.split(/[+-/*()]/);
var operations = input.split(/[^+-/*()]/);
var output = "";
vars = vars.map(x=>{
return x+"1";
});
for(var i=0; i<operations.length; i++){
output += operations[i]+""+((vars[i])?vars[i]:"");
}
return output;
}
Run Code Online (Sandbox Code Playgroud)
例如:(12/x+3)*heyo返回:(1121/x1+31)*1heyo1但应该返回(121/x1+31)*heyo1
javascript ×3
function ×1
geometry ×1
loops ×1
onclick ×1
parameters ×1
pseudocode ×1
regex ×1
setattribute ×1
split ×1