使用Javascript启用和禁用输入字段

使用Javascript启用和禁用输入字段,javascript,css,forms,Javascript,Css,Forms,我写了一些简单的代码,可以在点击按钮时启用和禁用输入字段,但它没有响应。 请帮帮我 <html> <head> <script type="text/javascript"> function toggleEnable(el1, el2) { document.getElementByID(el1).disabled = true; document.getElementByID(el2)

我写了一些简单的代码,可以在点击按钮时启用和禁用输入字段,但它没有响应。 请帮帮我

<html>
<head>
    <script type="text/javascript">
        function toggleEnable(el1, el2) {
            document.getElementByID(el1).disabled = true;
            document.getElementByID(el2).disabled = true;
        }
    </script>
</head>
<body>
    <form>
        <table>
            <tr>
                <td><input id="input1" class="myText" type="text" placeholder="Row 1" /></td>
                <td><input id="input2" class="myText" type="text" placeholder="Row 1" /></td>
                <td><button onclick="toggleEnable('input1','input2')"> Enable/Disable </button></td>
            </tr>
            <tr>
                <td><input id="input3" class="myText" type="text" placeholder="Row 3" /></td>
                <td><input id="input4" class="myText" type="text" placeholder="Row 4" /></td>
                <td><button onclick="toggleEnable('input3','input4')"> Enable/Disable </button></td>
            </tr>
        </table>
    </form>
</body>
</html>

功能切换启用(el1、el2){
document.getElementByID(el1).disabled=true;
document.getElementByID(el2).disabled=true;
}
启用/禁用
启用/禁用

您的按钮正在提交表单,若要不提交表单,您必须使用
type=“button”
按钮,而且您的
getElementByID
拼写错误,其
getElementByID

<form>
    <table>
        <tr>
            <td><input id="input1" class="myText" type="text" placeholder="Row 1" /></td>
            <td><input id="input2" class="myText" type="text" placeholder="Row 1" /></td>
            <td><button type="button" onclick="toggleEnable('input1','input2')"> Enable/Disable </button></td>
        </tr>
        <tr>
            <td><input id="input3" class="myText" type="text" placeholder="Row 3" /></td>
            <td><input id="input4" class="myText" type="text" placeholder="Row 4" /></td>
            <td><button type="button" onclick="toggleEnable('input3','input4')"> Enable/Disable </button></td>
        </tr>
    </table>
</form>

您的按钮正在提交表单,若要不提交表单,您必须使用
type=“button”
按钮,而且您的
getElementByID
拼写错误,其
getElementByID

<form>
    <table>
        <tr>
            <td><input id="input1" class="myText" type="text" placeholder="Row 1" /></td>
            <td><input id="input2" class="myText" type="text" placeholder="Row 1" /></td>
            <td><button type="button" onclick="toggleEnable('input1','input2')"> Enable/Disable </button></td>
        </tr>
        <tr>
            <td><input id="input3" class="myText" type="text" placeholder="Row 3" /></td>
            <td><input id="input4" class="myText" type="text" placeholder="Row 4" /></td>
            <td><button type="button" onclick="toggleEnable('input3','input4')"> Enable/Disable </button></td>
        </tr>
    </table>
</form>

您的按钮正在提交表单,若要不提交表单,您必须使用
type=“button”
按钮,而且您的
getElementByID
拼写错误,其
getElementByID

<form>
    <table>
        <tr>
            <td><input id="input1" class="myText" type="text" placeholder="Row 1" /></td>
            <td><input id="input2" class="myText" type="text" placeholder="Row 1" /></td>
            <td><button type="button" onclick="toggleEnable('input1','input2')"> Enable/Disable </button></td>
        </tr>
        <tr>
            <td><input id="input3" class="myText" type="text" placeholder="Row 3" /></td>
            <td><input id="input4" class="myText" type="text" placeholder="Row 4" /></td>
            <td><button type="button" onclick="toggleEnable('input3','input4')"> Enable/Disable </button></td>
        </tr>
    </table>
</form>

您的按钮正在提交表单,若要不提交表单,您必须使用
type=“button”
按钮,而且您的
getElementByID
拼写错误,其
getElementByID

<form>
    <table>
        <tr>
            <td><input id="input1" class="myText" type="text" placeholder="Row 1" /></td>
            <td><input id="input2" class="myText" type="text" placeholder="Row 1" /></td>
            <td><button type="button" onclick="toggleEnable('input1','input2')"> Enable/Disable </button></td>
        </tr>
        <tr>
            <td><input id="input3" class="myText" type="text" placeholder="Row 3" /></td>
            <td><input id="input4" class="myText" type="text" placeholder="Row 4" /></td>
            <td><button type="button" onclick="toggleEnable('input3','input4')"> Enable/Disable </button></td>
        </tr>
    </table>
</form>

功能切换启用(id){
var textbox=document.getElementById(id);
if(textbox.disabled){
//如果禁用,请执行此操作
document.getElementById(id).disabled=false;
}否则{
//在这里输入代码
document.getElementById(id).disabled=true;
}
}

启用/禁用
启用/禁用
功能切换启用(id){
var textbox=document.getElementById(id);
if(textbox.disabled){
//如果禁用,请执行此操作
document.getElementById(id).disabled=false;
}否则{
//在这里输入代码
document.getElementById(id).disabled=true;
}
}

启用/禁用
启用/禁用
功能切换启用(id){
var textbox=document.getElementById(id);
if(textbox.disabled){
//如果禁用,请执行此操作
document.getElementById(id).disabled=false;
}否则{
//在这里输入代码
document.getElementById(id).disabled=true;
}
}

启用/禁用
启用/禁用
功能切换启用(id){
var textbox=document.getElementById(id);
if(textbox.disabled){
//如果禁用,请执行此操作
document.getElementById(id).disabled=false;
}否则{
//在这里输入代码
document.getElementById(id).disabled=true;
}
}

启用/禁用
启用/禁用
可能重复可能重复可能重复可能重复