JSP to realize shielding backspace key problem discussion _jsp programming

Source: Internet
Author: User
Tags tagname
Today involves a problem, in the query criteria in the JSP, there are text boxes to enter filter criteria, there are drop-down boxes to select the filter criteria. The contents of the input box can be deleted by pressing the "Backspace" key, but the Backspace function needs to be shielded in the dropdown box, otherwise the rollback function of the page is performed. The code is as follows
Copy Code code as follows:

<TD width= "350px;" > Company Name:
<input type= "text" name= "Filter_psname" id= "Psname" size= "the/>"
</td>
<TD width= "200px;" > Area:
<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" >

</td>

Find a section of the Internet screen backspace code as follows
Copy Code code as follows:

$ (document). KeyDown (function (e) {
var doprevent;
if (E.keycode = = 8) {
var d = E.srcelement | | E.target;
if (d.tagname.touppercase () = = ' SELECT ') {
doprevent = D.readonly | | d.disabled;
}
Else
Doprevent = true;
}
Else
Doprevent = false;
if (doprevent)
E.preventdefault ();
});

The following questions were found:
The Drop-down box D.tagname gets the label name also input. Therefore can not achieve the above demand.
After a careful study, the following code
Copy Code code as follows:

The BACKSPACE key operation of the screened dropdown box
$ (document). KeyDown (function (e)
{
Get key code for keyboard
var K=e.keycode;
Gets the label object for the operation
var Obj=e.target | | E.srcelement;
Gets the value of the read-only property of an object
var vreadonly = Obj.getattribute (' readonly ');
Return FALSE if the key is "backspace" and the label object's read-only property is not empty (select label default readonly= "ReadOnly")
if (k==8 && vreadonly!=null) {
return false;
}
});

To achieve the above needs, there should be a better way, I hope friends see can give tips or talk to 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.