查看: 2526|回复: 0

[前端框架] JS 操作 Select相关功能测试

[复制链接]

2480

主题

1280

回帖

8万

积分

管理员

PLM之家站长

积分
82278
QQ
发表于 2019-11-4 20:15:32 | 显示全部楼层 |阅读模式

请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!

您需要 登录 才可以下载或查看,没有账号?注册

×
4 N- Q& M3 C% r4 p
$ M9 l) ~! o7 V- w, i7 C& q1 o, X6 H4 i
JS 操作 Select相关功能测试
, @0 T2 @0 O& u7 H$ o1 a5 x; K9 U/ x3 r7 ~2 p# v2 l' W8 M. a! p2 Z0 P) \
[mw_shl_code=html,true]<html lang="en">2 d9 l. |# b0 K- |0 h
" `% [% y( n& j$ |, l  H
<head>4 c+ D$ n% }8 J
    <meta charset="UTF-8">
, w, l$ t2 p- @, H    <meta name="viewport" content="width=device-width, initial-scale=1.0">3 d' |" r: T+ w) f" A8 G
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
4 `) X+ a* x) i+ _    <title>Document</title>
! y- r' G: s4 L, U' _! A, y    <style>' M$ a# ?/ Z# a/ X* x$ o4 H
        * {
' R$ }* @: e7 d) J2 s            font-size: 10px;
: O8 P4 k$ c+ S5 l            line-height: 24px;8 {  c( Q. ^& F  \. o  ?; e# h
        }8 b6 P5 m. U+ K& [# B
    </style>
/ d( O8 z2 P' T3 b</head>
8 o) A2 h( X9 ]% Z# j3 D( H* R8 T! b- a0 Z
<body>
4 E1 d7 e2 U! V3 x0 ]$ ]: i3 Z    //this is for the select test
4 O0 m, ~0 ?7 i8 e5 v& c    <form id='myForm' action="submit" method="GET">
# o8 B  y8 V! \# t* a% T        <input type="text" id="inpuTChange" />
1 A6 v8 Q( ]+ u5 U! U( C        <select name="selectFruits" id="mySelect">
; J) ^* ]% S& U5 J7 z            <option value="Orange1">Orange</option>% v* ]$ Z$ s, e& z. ~, y/ e" Y- m' e
            <option value="Apple2">Apple</option>4 d+ _2 z- O. ]4 t
            <option value="Banana3">Banana</option>
/ o& A8 X" r) M- v+ T        </select>
1 F) q; ~, r+ T# m) ?2 q/ g$ ?        <br>8 |% n. `4 a5 P0 \) E9 p* d
        <input type="button" value="disable"># p% Q6 T" n/ O, ?, H6 e2 Y# {. B. L
        <input type="button" value="Able">/ E* A- ?- M# t+ K! g6 J9 d
        <input type="button" value="getValues">
: H# ^0 E; }: l6 s6 j9 X6 ]/ u        <input type="button" value="editValues">5 V; H# X- m, o% V- @; W& l
        <input type="button" value="addValues">
, e6 y5 G- K% y" `        <input type="button" value="removeValues">8 C/ K' E& o, A6 D) p. f
        <br>
0 l+ V" c0 A; E0 B) ~( R, Y& O0 z1 M
    </form>& m1 g- G2 d0 h

8 b6 x  W' s- z1 L+ |    <p id="demoInput"></p>
2 i; o( M+ ^5 W$ s( \* @
8 ]2 h# m1 s- z5 U* w! z* W  d5 j; l( f3 c  ~) p4 k
    <script>$ U- J3 a" H: T+ L9 j
        function disableFunc() {% @) R% |3 m. w7 Z5 O6 e# p
            document.getElementById('mySelect').disabled = true
+ M+ |$ A0 m  J% n$ v        }
- N) r" p' b7 I        function ableFunc() {
4 Z. Y- k' _9 _' R( S  _4 C            document.getElementById('mySelect').disabled = false
" K8 t% Y7 \) M7 |        }1 Z* H' F3 c$ s: P4 p: \
        function getValues() {1 g9 \5 r, J# W6 a
            var text = '<ul>'
' {2 P0 q/ k) j9 Q0 o/ Y            var x = document.getElementById('mySelect')
" G9 [3 B% s2 S" c* ]9 [/ T            for (var i = 0; i < x.length; i++) {& J6 L% x/ [3 r  u0 L
                text += '<li>' + x.text + '</li>'
' j& M* k, b# ^            }
5 ^+ H" ]8 p: ?4 Q            text += '</ul>'
: A, C3 ?/ E7 _! L  ^9 Y7 j            document.getElementById('demoInput').innerHTML = text
& j+ d% ?. a5 P* K0 S        }
# Z2 P9 Q- P8 O" o% `1 R- Q1 Z( l  y
        function editValue() {. ^! Z0 T% ?3 m( \# O+ B2 Z
            var mySelected = document.getElementById('mySelect')
1 Z' K; z: X0 o5 N            var selectedIndex = mySelected.selectedIndex$ I- Y$ E6 p! Y' P
            mySelected[selectedIndex].text = document.getElementById('inputChange').value; X; }- T; u3 R& ^7 ?- q
        }  t% R; p' e( u, w% L  X/ t

! C3 ?! z* Q, ^) d        function removeValue() {
& n+ {0 m6 R1 y/ Z, g            var myselect = document.getElementById('mySelect')- J5 i* \" M# x6 {7 ?) Q: _
            var selectedIndex = myselect.selectedIndex4 ~; d' n$ J  p9 Y9 R! i
            myselect.remove(selectedIndex). p: y( C1 k5 u  W) }
        }" L( D, I" z& Z$ J
        function addValue() {
  v, B* R4 @, ~# k3 i$ E6 ~/ A            var myselect = document.getElementById('mySelect')% v; N' _4 i" |, ]' {
            var addvalue = document.getElementById('inputChange').value
( C% f4 _9 V: o/ |4 v            myselect.options.add(new Option(addvalue,"value"))
" x$ Z2 O' ^5 b9 M) _4 g$ F  Y        }
: _  Q$ E9 c8 C& m    </script>; Q7 Z8 Y6 d2 E; h% w7 t+ \
</body>
+ L! C* s: c7 |- b
/ W9 u# Q( M- m4 w</html>[/mw_shl_code]
% W2 b+ e" A& U, q: f/ \
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 doTeam.tech
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

在本版发帖
关注公众号
QQ客服返回顶部