How to Implement the unblocking backspace key in jsp

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.