Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在文本框可以只读的情况下,属性可以是切换形式吗?_Javascript_Jquery_Html - Fatal编程技术网

Javascript 在文本框可以只读的情况下,属性可以是切换形式吗?

Javascript 在文本框可以只读的情况下,属性可以是切换形式吗?,javascript,jquery,html,Javascript,Jquery,Html,我想要两个文本框字段的只读属性。单击“#text1”时“#text2”应具有false readonly属性,单击“#text2”时“#text1”readonly将为false。默认情况下,两个文本框均为true readOnly。可能吗 <input type="text" id="text1" /> <input type="text" id="text2" /> 试试这个: $('#text1').focus(function(){ $('#text2

我想要两个文本框字段的只读属性。单击“#text1”时“#text2”应具有false readonly属性,单击“#text2”时“#text1”readonly将为false。默认情况下,两个文本框均为true readOnly。可能吗

<input type="text" id="text1" />
<input type="text" id="text2" />

试试这个:

$('#text1').focus(function(){
    $('#text2').attr('readonly',true);
    $('#text1').attr('readonly',false);
});
$('#text2').focus(function(){
    $('#text1').attr('readonly',true);
    $('#text2').attr('readonly',false);
});
试试这个

        <input type="text" id="text1" onclick="text1()" /> 
        <input type="text" id="text2" onclick="text2()" />

        <script type="text/javascript">
            function text1() {
                $("#text1").prop("readonly", true);
                $("#text2").prop("readonly", false);
            }

            function text2() {
                $("#text2").prop("readonly", true);
                $("#text1").prop("readonly", false);
            }
        </script>

函数text1(){
$(“#text1”).prop(“只读”,true);
$(“#text2”).prop(“只读”,false);
}
函数text2(){
$(“#text2”).prop(“只读”,true);
$(“#text1”).prop(“只读”,false);
}

那么,您希望文本框是只读的,除非用户关注它们?那会实现什么?是的@guri那就是..你可以简单地通过灰色文本框背景设置一个只读的幻觉。这对我不起作用。如果您有任何其他技术选择,请给我举个例子