|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
# L+ ~, i6 b; ~3 p9 A9 W
( }" r |4 L- I: O$ j e% Z. U5 \% n$ H* q3 EJS 操作 Select相关功能测试 C' ?4 ?" e. C* f6 j4 W( u
5 k# A1 G5 Y7 ?$ w0 E. ^ G3 r( Z
[mw_shl_code=html,true]<html lang="en">
) O7 [8 Y, c1 t+ R7 [7 B( @/ `
7 m# q1 x7 H c0 t& L<head>, y4 H% w- m" r6 j$ N4 N) d
<meta charset="UTF-8">5 O2 W6 R9 w: a" i3 H7 q
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7 v0 P2 o+ u3 X+ @7 S9 i* y <meta http-equiv="X-UA-Compatible" content="ie=edge">
$ i( [9 ~/ b% E# s/ a4 i1 K <title>Document</title>
9 q5 @+ ]/ X% X9 i' O% J3 j, m <style>/ g J, Z1 V V! `) t- K, Q( J3 u
* {! [8 a1 B) w- L4 A( l+ ]' k
font-size: 10px;
D, g' f" O% f) Y- \6 `3 ^( D line-height: 24px;- \' _: P7 K- R3 o- L
}) H; H4 L' u7 q5 b& t
</style>" M( G- _1 I c7 W' ~7 L; v
</head>; d3 F% N: h1 E ]3 w' g
2 B3 ]* h0 C$ X( l' H6 F<body>, O* ], x9 w) N7 d- I+ R
//this is for the select test
" C" U$ l; q5 q7 `8 `6 X7 Y' _1 c7 Z <form id='myForm' action="submit" method="GET">% f) g2 ?# O ^: j0 n7 Z- ]5 l
<input type="text" id="inpuTChange" />
8 W$ q6 ~ X$ x) }! d- h <select name="selectFruits" id="mySelect">: A" Y5 O- X% P: u/ }' [. W
<option value="Orange1">Orange</option>5 `, t' y! F% B+ n8 h
<option value="Apple2">Apple</option>
- N/ c! K: _+ U <option value="Banana3">Banana</option>4 [9 y0 ?* @! ?) f
</select>
u+ n9 Q3 i! b4 h2 H% ~9 u <br>
, _9 n: N0 @6 e1 m <input type="button" value="disable">+ K- Q" a9 U- ?3 A% v6 x- y' e& q0 M
<input type="button" value="Able">
7 F. F/ F5 E, D! k- R) O6 o <input type="button" value="getValues">
# d, G0 i* o' i% g( P <input type="button" value="editValues">0 m, o. X: U) @" s& g
<input type="button" value="addValues">
& ]" p; v; V; N1 e" X% W <input type="button" value="removeValues">+ @4 p! H( o# e9 i8 y6 F
<br>. W8 M' ~) p( n' \
* w; n" G: H( F4 D. Y$ @9 }3 w </form>
; Z |8 g( O2 j- _, M! ? Q" q, [0 D M, i! \ K$ D* k
<p id="demoInput"></p>
* `. h5 \6 _: Y; X' I1 l+ S" |4 `* ?, S# p: [
. b2 T7 \. A$ u Y! w, Q: { <script>
+ u3 d3 {( [! `4 U V function disableFunc() {
7 A s2 C/ t8 ` document.getElementById('mySelect').disabled = true: n% H+ J8 [2 d$ W! k
}
Y7 l( M0 H# k& T# ^ function ableFunc() {
) ]3 j& T8 E, ] document.getElementById('mySelect').disabled = false
, s) x$ a( T, q) I }
& r. v) h r9 p+ d function getValues() {& A# e! z E9 Z
var text = '<ul>'2 w2 b2 g8 {- v: r
var x = document.getElementById('mySelect')
2 q. K( w2 O% h# `( e( g/ Z0 S1 v for (var i = 0; i < x.length; i++) {! e0 A+ S8 q& v" x
text += '<li>' + x.text + '</li>'
. Y% @ w3 ?+ v2 e3 k# W }
" G D# J& K5 f5 O. v' }1 D text += '</ul>'2 o- V3 y8 P m, ]9 k. j
document.getElementById('demoInput').innerHTML = text
5 B3 _: T" x2 l6 N% d) R } P+ G. B+ V4 W
9 W& I! M; u! c9 T: O function editValue() {# E! n% I, V$ K& c/ ?
var mySelected = document.getElementById('mySelect')
$ l. i3 `3 a& r, D var selectedIndex = mySelected.selectedIndex
0 ^ y- r7 q! S3 ]) m mySelected[selectedIndex].text = document.getElementById('inputChange').value0 a$ \4 M' X: k
}+ H4 \* A1 l9 @: y
8 a8 u- u7 f& ]
function removeValue() {- @4 h5 P L4 D6 v$ m; H
var myselect = document.getElementById('mySelect')
+ C, z/ X, x2 h6 }5 ^ var selectedIndex = myselect.selectedIndex
. y; z& c) r, v6 N6 M! o6 a( y+ ~ myselect.remove(selectedIndex)$ I7 M& k# J7 S9 m4 P. g
}
+ e8 N6 N5 j5 q% m+ w+ T { function addValue() {
9 A& x3 w& I. j! M6 C" ` var myselect = document.getElementById('mySelect')& N- A- P/ |5 I
var addvalue = document.getElementById('inputChange').value
' Q5 k% S2 [! b& z$ V0 e, R myselect.options.add(new Option(addvalue,"value"))1 _! l8 p* [. X9 {2 n
}
7 ]' I' o# I+ k$ J </script>- T0 w0 Z( f/ S* ?! b4 D: z0 `
</body>$ f9 v/ Z3 u& O' Z
8 S7 I7 Y5 ~$ t1 w6 O( v* b A</html>[/mw_shl_code]' a* `+ O1 S: w7 l
|
|