[英]How to disable cursor in text box and toggle its values on click?
我有一系列文本框,如下所示,我必須禁用光標,並在單擊文本框時在“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想要文本框中的任何光標,是否可以完全刪除它
在readonly textarea中禁用游標的另一種簡單方法是
<textarea readonly onfocus="this.blur()">Content</textarea>
我在Firefox ESR 24.1.0和chorme 30.0.1599.101 m中進行了測試。 在chrome中,onfocus =“this.blur()”無關緊要
編輯
<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'時隱藏光標,
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.