Today, we have a problem. In the query conditions in jsp, you can enter filtering conditions in the text box, or Select filtering conditions in the drop-down box. The content in the input box can be deleted by pressing the "Backspace" key, but the backspace function needs to be blocked in the drop-down box. Otherwise, the page rollback function will be executed. The Code is as follows:
Copy codeThe Code is as follows:
<Td width = "350px;"> Company Name:
<Input type = "text" name = "filter_psName" id = "psName" size = "40"/>
</Td>
<Td width = "200px;"> region:
<Select name = "filter_regionCode" id = "regionName" theme = "simple"/>
</Td>
<Td>
<S: radio onclick = "query ();" name = "filter_status" theme = "simple"> </s: radio>
</Td>
<Td valign = "middle" align = "center">
Query
</Td>
I found a code on the Internet to block the backspace key:
Copy codeThe Code is as follows:
$ (Document). keydown (function (e ){
Var doPrevent;
If (e. keyCode = 8 ){
Var d = e. srcElement | e.tar get;
If (d. tagName. toUpperCase () = 'select '){
DoPrevent = d. readOnly | d. disabled;
}
Else
DoPrevent = true;
}
Else
DoPrevent = false;
If (doPrevent)
E. preventDefault ();
});
The following problems are found:
In the drop-down box, the tag name obtained by d. tagName is also INPUT. Therefore, the above requirements cannot be met.
I carefully studied the following code:
Copy codeThe Code is as follows:
// Block the backspace key operation in the drop-down list
$ (Document). keydown (function (e)
{
// Obtain the keyboard key CODE
Var k = e. keyCode;
// Obtain the tag object of the operation
Var obj=e.tar get | e. srcElement;
// Obtain the value of the read-only attribute of the object
Var vReadOnly = obj. getAttribute ('readonly ');
// If the key is "backspace" and the read-only attribute of the tag object is not empty, return false (select tag readonly = "readonly" by default ")
If (k = 8 & vReadOnly! = Null ){
Return false;
}
});
There should be a better way to achieve the above requirements. I hope my friends can give me a prompt or discuss with each other.