Javascript 在html中交替启用和禁用按钮
当用户打开页面时,更新按钮必须禁用,编辑按钮应启用,并且不应有机会编辑文本字段 当用户单击编辑按钮时,必须启用更新按钮,禁用编辑按钮,并且用户只能编辑Javascript 在html中交替启用和禁用按钮,javascript,java,html,frontend,Javascript,Java,Html,Frontend,当用户打开页面时,更新按钮必须禁用,编辑按钮应启用,并且不应有机会编辑文本字段 当用户单击编辑按钮时,必须启用更新按钮,禁用编辑按钮,并且用户只能编辑FirstName和LastName,但不能编辑EmpId字段。 请帮我做这件事 这是我代码的一部分:- <!DOCTYPE html> <html> <head> <meta charset="ISO-8859-1"> <title>Insert title here</title
FirstName
和LastName
,但不能编辑EmpId
字段。
请帮我做这件事
这是我代码的一部分:-
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
<script type="text/javascript">
function func1(){
document.getElementById("update").disabled=true;
}
function btnUpdate(){
if(document.getElementById("edit").clicked=true;){
document.getElementById("update").disabled=false;
}
}
</script>
</head>
<body onload="func1()">
<table rules="all" border="" style="position: absolute;left: 337px;top: 125px;">
<tr><td id="EmpID">EmpID:</td><td><input type="text" value="MGIS107"></td></tr>
<tr><td id="FirstName">FirstName:</td><td><input type="text" value="Vikas"></td></tr>
<tr><td id="LastName">LastName:</td><td><input type="text" value="Dubbaka"></td></tr>
<input type="button" value="Update" id="update">
<input type="button" value="Edit" id="edit" onclick="btnUpdate()">
</body>
</html>
在此处插入标题
函数func1(){
document.getElementById(“更新”).disabled=true;
}
函数btnUpdate(){
if(document.getElementById(“编辑”).clicked=true;){
document.getElementById(“更新”).disabled=false;
}
}
EmpID:
名字:
姓氏:
尝试以下方法:
var empId=document.getElementById(“empId”);
var fName=document.getElementById(“名字”);
var lName=document.getElementById(“LastName”);
empId.disabled=true;
函数func1(){
document.getElementById(“更新”).disabled=true;
fName.disabled=true;
lName.disabled=true;
}
函数btnUpdate(el){
document.getElementById(“更新”).disabled=false;
el.disabled=真;
fName.disabled=false;
lName.disabled=false;
}
EmpID:
名字:
姓氏:
您可以使用readonly等属性,并根据您提到的条件动态删除。我不知道这里有什么困难。您面临的任何具体问题?请记住,这样做只是为了让用户满意;您需要验证服务器端的“EmpId”是否未更改。如果我编写了一个函数,那么我将禁用更新按钮,当我为编辑按钮编写onclick函数时,这两个按钮都已启用。@Mikkel Bachamann我是初学者,交给我的任务是只在客户端执行。