我有一系列文本框,如下所示,我必须禁用光标,并在单击文本框时在“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
更新:
Idont想要文本框中的任何光标,是否可以将其完全删除
答案 0 :(得分:2)
在readonly textarea中禁用游标的另一种简单方法是
<textarea readonly onfocus="this.blur()">Content</textarea>
我在Firefox ESR 24.1.0和chorme 30.0.1599.101 m中进行了测试。在chrome中,使用onfocus =“this.blur()”
无关紧要答案 1 :(得分: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
}
});
});
答案 2 :(得分: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>
我真的不明白你,因为我的英语不好但是这段代码,当空白时隐藏光标,当输入包含&#39; X&#39;时,隐藏光标,