PLM之家PLMHome-工业软件与AI结合践行者

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

[复制链接]

2019-11-4 20:15:32 2178 0

admin 发表于 2019-11-4 20:15:32 |阅读模式

admin 楼主

2019-11-4 20:15:32

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

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

x

# J/ ?2 _. Z3 l  w9 f4 S" a5 G  K: h" P5 }
JS 操作 Select相关功能测试
8 p: C: ?2 x$ E% ^3 ~
6 ^, T$ j1 m4 H0 y! ~[mw_shl_code=html,true]<html lang="en">
7 W  U2 h& ^: E- W9 q" K
( h( g: V1 C/ e1 D- R<head>
% J6 W5 E- @( H    <meta charset="UTF-8">
) a$ E1 K; T5 Z+ h. K) Q9 N    <meta name="viewport" content="width=device-width, initial-scale=1.0">, N( ]: P& W9 z7 e6 b" T
    <meta http-equiv="X-UA-Compatible" content="ie=edge">7 j8 M" B1 v' E, Q' I4 O- }
    <title>Document</title>
# o& V' `! U2 I) q- g    <style>
1 w+ t4 w: h$ M. W8 s% S        * {% q" F* \6 n& q% ]) _) @
            font-size: 10px;
. w9 x! ~; U' S            line-height: 24px;
: B2 ^7 `" Z: ?/ F+ T        }' |  T' R$ `. T9 L" \
    </style>
( T1 p. J9 B8 R1 T# v</head>
/ I& e5 I5 j9 z5 Z' N: z$ R$ {; _
7 e! N+ F, s  n8 e/ ^7 P<body>
3 ?7 M' M- W+ Z. a    //this is for the select test
$ D: K5 E! f/ ?    <form id='myForm' action="submit" method="GET">5 a. X, T1 s9 G
        <input type="text" id="inpuTChange" />' B& J7 M, R6 u  O
        <select name="selectFruits" id="mySelect">* b; O: e+ W. c2 p/ a
            <option value="Orange1">Orange</option>
3 Q& a+ X  D# F7 h  x            <option value="Apple2">Apple</option>
/ P+ V5 U) e$ |5 a            <option value="Banana3">Banana</option>
* G8 P: F* Y; I' q% C; s8 y5 r- @, C        </select>
1 b. v& K7 s: n) w4 j* j: \        <br>
9 Q# m( S1 i/ P/ w3 h' y  u        <input type="button" value="disable">
$ W9 `/ F' A- l3 K. V- i        <input type="button" value="Able">& e# [+ h/ k" z6 Q1 I" q0 i
        <input type="button" value="getValues">2 _) C' A4 A  s2 S, U. I: z3 Z, |
        <input type="button" value="editValues">9 ?4 W. Q4 P( i3 Z
        <input type="button" value="addValues">! r& Y+ i6 M% m* \) Z* }6 P0 e# w
        <input type="button" value="removeValues">
+ I# P2 `% H( P0 f+ A$ e4 |        <br>2 V) X" e  d+ V

" F: h. m/ W0 s* i& a9 s    </form>0 T9 J7 k4 m# o
; c( a2 |4 Q4 t/ O; {
    <p id="demoInput"></p>
# F% I# R; K" ^+ y" K8 h5 T3 u; B! T& ]7 B

- s0 c& P" k+ }$ w! x& Z    <script>
3 W1 _) ?: ~6 J% I        function disableFunc() {( M, M! B+ H; p
            document.getElementById('mySelect').disabled = true$ \/ \3 t8 Z( n5 |8 E
        }& \" J% G0 h' `- ^6 I3 q
        function ableFunc() {# N5 m% Z! B: Z7 h. Z
            document.getElementById('mySelect').disabled = false
- Y! W$ r2 L4 A  ^  g% R        }: M( Y6 ]0 D' z- ^
        function getValues() {
9 |8 x$ t1 ]( S% B7 w; b. r  C            var text = '<ul>'1 ?( m4 Z6 W: e$ d' z% h
            var x = document.getElementById('mySelect')
) |- C& u( o' ^7 f; m( k) [" f- |            for (var i = 0; i < x.length; i++) {5 A1 b' e4 E9 F6 N) X8 @" V
                text += '<li>' + x.text + '</li>'
+ @0 |& c7 h. R0 e            }
- ~$ {# R- d% B- {            text += '</ul>'1 k. C) L! T8 t; i) `; l' z  k& i
            document.getElementById('demoInput').innerHTML = text
7 |! y' d" G  Y7 a6 J        }
3 O. n' q$ c) Y
4 J6 m* I; X4 P. G        function editValue() {" [# q1 A( Q% ^- k- v# B
            var mySelected = document.getElementById('mySelect')
6 W$ ^* b' D9 `  e            var selectedIndex = mySelected.selectedIndex  X2 j$ q9 c9 ?' C5 l4 J
            mySelected[selectedIndex].text = document.getElementById('inputChange').value- w# \. F$ O7 C
        }
; R! B8 _1 y" G+ I: J" b( E
3 B; r9 x3 G* x% I7 e        function removeValue() {4 q* M7 ~& v" i! a- x. ?) M  z
            var myselect = document.getElementById('mySelect')% P' }$ F% {, p1 P
            var selectedIndex = myselect.selectedIndex
; A+ e  s% q! o$ G7 M4 _! m; W            myselect.remove(selectedIndex)
# w6 _. V* F( U/ z$ w" c        }& p/ @0 H) X+ x/ N8 Z
        function addValue() {
% j, Q" v; I9 Y9 B/ I            var myselect = document.getElementById('mySelect')
% Y' i0 D: I# y8 C3 u6 i            var addvalue = document.getElementById('inputChange').value
0 Y$ \: c* {' `$ U" z: L% D3 i! X/ D            myselect.options.add(new Option(addvalue,"value"))$ M, T' J7 ]$ B" O
        }# F& Y( w' [2 E8 }) r  _4 f
    </script>
% h3 Q6 Q* r$ q8 [9 I, j: @# C</body>
8 R0 q0 r+ e1 ]0 W8 Q
, {+ [, _. g6 C# [</html>[/mw_shl_code]
& P9 D: U0 P1 Z; D
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 doTeam.tech
回复

使用道具 举报

发表回复

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

返回列表 本版积分规则

  • 发布新帖

  • 在线客服

  • 微信

  • 客户端

  • 返回顶部

  • x
    温馨提示

    本网站(plmhome.com)为PLM之家工业软件学习官网站

    展示的视频材料全部免费,需要高清和特殊技术支持请联系 QQ: 939801026

    PLM之家NX CAM二次开发专题模块培训报名开始啦

    我知道了