0

我有一系列如下所示的文本框,当您单击文本框时,我必须在其中禁用光标并在“X”和“”之间切换其值。这是我写的代码:

HTML 代码:

<input type="text" name="loan1" id="crossCheck1" class="crossCheck" onfocus="this.blur()" readonly="readonly" maxlength='1' style=" width: 13px; height:13px; border-style:none;font-weight:bold; font-family:Arial Narrow; font-size:14px; color:#000000;margin-left:85px;cursor:hand"/>

<input type="text" name="loan2" id="crossCheck2" class="crossCheck" onfocus="this.blur()" readonly="readonly" maxlength='1' style=" width: 13px; height:13px; border-style:none;font-weight:bold; font-family:Arial Narrow; font-size:14px; color:#000000;margin-left:85px;cursor:hand"/>

<input type="text" name="loan3" id="crossCheck3" class="crossCheck" onfocus="this.blur()" readonly="readonly" maxlength='1' style=" width: 13px; height:13px; border-style:none;font-weight:bold; font-family:Arial Narrow; font-size:14px; color:#000000;margin-left:85px;cursor:hand"/>

Javascript:

$(document).ready(function() {
        $( ".crossCheck" ).click(function() {

            var cross =  $('#crossCheck1').val();
            var check = 'X' ;
            if(cross == "" ){
                document.getElementById("crossCheck1").value= check;
            }else{
                document.getElementById("crossCheck1").value= '';
            }

        });  
});

1. 这里,光标在内容改变的时候是可见的,你能告诉我一种去除光标的方法吗?

2.你能告诉我如何只改变被点击的文本框的值吗?

演示Here

更新:

我不希望文本框中有任何光标,是否可以将其完全删除

4

3 回答 3

3

在只读文本区域中禁用光标的另一种简单方法是

<textarea readonly onfocus="this.blur()">Content</textarea>

我在 Firefox ESR 24.1.0 和 chorme 30.0.1599.101 m 中对此进行了测试。在 chrome 中,拥有 onfocus="this.blur()" 并不重要

于 2013-11-05T08:44:37.440 回答
0

已编辑

<html>
<head>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script>
jQuery(document).ready(function() {
        jQuery(".crossCheck").click(function() {
            var cross =  jQuery(this);
            var check = 'X' ;
            if(cross.val() == "" ){
                cross.val(check);
                cross.css("cursor","default");
            }else{
                cross.val('');
                cross.css("cursor","none");
            }
        });  
  });
  </script>
</head>
<body>
<input type="text" name="loan1" id="crossCheck1" class="crossCheck" onfocus="this.blur()" readonly="readonly" maxlength='1'/>

<input type="text" name="loan2" id="crossCheck2" class="crossCheck" onfocus="this.blur()" readonly="readonly" maxlength='1' />

<input type="text" name="loan3" id="crossCheck3" class="crossCheck" onfocus="this.blur()" readonly="readonly" maxlength='1'/>
</body></html>

我真的不明白你,因为我的英语不好但是这段代码,当输入包含'X'时隐藏光标,当输入包含'X'时返回,

于 2013-08-29T06:32:35.503 回答
0
$(document).ready(function() {
    $( ".crossCheck" ).click(function() {

        var cross =  $(this).val();
        var check = 'X' ;
        if(cross == "" ){
            $(this).val(check).css("cursor","none");// set value and remove cursor
        }else{
             $(this).val().css("cursor","pointer");// set cursor
        }

    });  
});

在 jquery 中引用css

于 2013-08-29T06:31:14.363 回答