当用户按下 del 键时,我想要按下一个按钮。我有这个:
document.getElementById('result').onkeypress=function(e){
//This works, when the user presses enter, submitbtn is clicked
if(e.keyCode==13){
document.getElementById('submitbtn').click();
}
//This doesn't, but it is the same as the code above
else if(e.keyCode==46){
document.getElementById('clrbtn').click();
}
}
这是我的HTML:
<input id="result" type="number" min="0" placeholder="0">
<button id="submitbtn" onclick="submit()">Submit</button>
<button id="clrbtn" onclick="clr()">Clear</button>
我尝试了e.which
和e.preventDefault()
,但都没有效果。我查看CTRL keyCode (17) not working in JavaScript?,然后检查是否有delKey
,类似于ctrlKey
,但没有。import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileNotFoundException;
public class Animals {
String line;
int i = 0;
BufferedReader animals = new BufferedReader(new FileReader
("//Documents//animals.txt"));
string animalChoices () {
string animalChoice = while ((line = animals.readLine()) != null)) {
for (i = 0, i < 4, i++) {
System.out.print(line);
}
}
}
string displayAnimals () {
string displayAnimal = while ((line = animals.readLine()) != null) {
for (i=0, i<4, i++) {
if (line.contains("*****")) {
string alertLine = line.replace("*****", "ALERT!!! ");
system.out.println(alertLine);
}
else if {
system.out.println(line);
}
}
}
}
}
。
我如何使删除keyCode,我肯定是46,使用我的代码?有没有更好的方法?
提前谢谢!
答案 0 :(得分:0)
当您按Enter键时,您的表单正在提交,但它不需要对您的代码执行任何操作,这就是删除键无法正常工作的原因 你应该用onkeydown替换onkeypress