Home > Web Front-end > JS Tutorial > body text

Some instructions for jquery select drop-down box operations_jquery

WBOY
Release: 2016-05-16 18:30:21
Original
1064 people have browsed it
Copy code The code is as follows:

//==========Test code= ==============

Drop-down box test








< asp:Button ID="butSave" runat="server" onclick="butSave_Click" Text="Button" />


//=== =======End Test code====================

Test description:
A: Static select item
Static select items (can be filled through server-side scripts) can be set directly using $("#drop-down box id").val (selected value).
After setting, use $("# drop-down box id" ).val(); can obtain its value correctly.

B: When there is a static
that contains a dynamically created option, use $("#selectId").val()
Dynamically created (including a static option such as: ), you can pass
1.setTimeout("$("#drop-down box id") .val(" value ")",1) setting.
But after using setTimeout, it is incorrect to use $("#drop-down box id").val(); to get the value. Of course, usually your code context The value value is retained.
There is no need to retrieve it through .val(). The disadvantage of setTimeout is that it is executed asynchronously. The context when setTimeout is executed is usually not the current function domain.

2. Use try{$(" #Drop-down box id").val();}catch(e){} to block errors,
This can run normally in Firefox and IE6.0, but there will be problems with IE6.0's value.
C: All are created dynamically
In this case, try is used and there is no setting in IE6.0.

In addition, IE6.0 cannot automatically adjust the select width for dynamically created drop-down items, which requires Manual adjustment.
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template