1
如果在HTML中達到該文本框的最大長度,我可以給輸入類型文本提供工具提示嗎?最大輸入長度達到時的工具提示
如果在HTML中達到該文本框的最大長度,我可以給輸入類型文本提供工具提示嗎?最大輸入長度達到時的工具提示
是的,你可以設置工具提示文本框中
/*
txtname id of youe textbox
val is value of textbox
ccount is max length of textbox.
if ccount is set to 4 then
if value of textbox exceed then 4 then it will show tooltip
*/
function txtToolTip(txtname, val, ccount) {
var txtTool = document.getElementById(txtname);
if (txtTool.value.length > ccount) {
//Setting tool tip value.
txtTool.title = txtTool.value;
}
}
您的輸入框是
<input type="text" name="txtnm" id="txtnm" onkeyup="txtToolTip(this.id, this.value, 4);"/>
你可以使用我的代碼對您的問題解決:
<!doctype html>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Input Key Filter Test</title>
\t <meta name="author" content="Andrej Hristoliubov [email protected]">
\t <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
\t
\t <!-- For compatibility of IE browser with audio element in the beep() function.
\t https://www.modern.ie/en-us/performance/how-to-use-x-ua-compatible -->
\t <meta http-equiv="X-UA-Compatible" content="IE=9"/>
\t
\t <link rel="stylesheet" href="https://rawgit.com/anhr/InputKeyFilter/master/InputKeyFilter.css" type="text/css"> \t \t
\t <script type="text/javascript" src="https://rawgit.com/anhr/InputKeyFilter/master/Common.js"></script>
\t <script type="text/javascript" src="https://rawgit.com/anhr/InputKeyFilter/master/InputKeyFilter.js"></script>
\t
</head>
<body>
\t <h1>Text field. String length is limited to 10 sumbols</h1>
Max Length input field:
<input type='text' id='maxLength' maxlength ="11" />
New string: <span id="newString"></span>
<script>
CreateMaxLengthFilter('maxLength', {
formatMessage: 'Length limit to %s sumbols'
, onerror: function (elementInput) {
elementInput.focus();//except Firefox
}
, onblur: function (event) {
document.getElementById('newString').innerHTML = event.target.value;
}
});
</script>
</body>
</html>
非常感謝....它的工作.... – apoorvabade 2010-11-16 07:05:31
它可以顯示固定?我的意思是當我將光標移動到該文本框時,現在出現tooltip?有沒有一種方法,我不斷顯示工具提示直到n,除非所需的一個字符被清除? – apoorvabade 2010-11-16 08:58:05