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

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

[复制链接]

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

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

admin 楼主

2019-11-4 20:15:32

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

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

x
- {# n: W0 d- \0 S. O: S! @- S
" W6 `0 [- S7 w. G9 b0 g  Y
JS 操作 Select相关功能测试3 o. v: X! b( B" Y5 U$ a

7 E1 x5 K8 `' v- ^; h+ w# t4 M[mw_shl_code=html,true]<html lang="en">
4 _/ n! F2 s2 r
& R" Q3 \6 u5 q<head>( M: ^% n; I! ?9 ?
    <meta charset="UTF-8">
- V( Z9 e* {0 }% s5 U' y    <meta name="viewport" content="width=device-width, initial-scale=1.0">
: g3 }0 O: T+ M5 M. T! s" j0 p    <meta http-equiv="X-UA-Compatible" content="ie=edge">) Z7 p2 I4 _4 J* R, g; C" V) D. @
    <title>Document</title>
/ b* b( v  [7 Q) u9 G% N- T    <style>
: o1 X, `- ~* b3 r$ K        * {( v# D% m4 r, I& o: i  q- d( d2 [
            font-size: 10px;/ o* m7 R2 h5 r4 N7 t. E, g+ B
            line-height: 24px;5 ~$ p7 l$ i) |5 M" ?& V* D8 t! _
        }  J" r( n9 d3 ~
    </style>
1 ?5 n6 \4 z# ?6 K0 Y6 [% I) T. x" H</head>
' f. t6 g9 y- ~* I5 H& i% C& Q+ ^( \
<body>
+ `" h9 |! y; C* N/ p! Q, S$ l    //this is for the select test
# y' P- V, m1 l: g1 y    <form id='myForm' action="submit" method="GET">
. y! X. L. g) F. d. r        <input type="text" id="inpuTChange" />9 l* C. k' S% @! c
        <select name="selectFruits" id="mySelect">
2 |% u9 N, h! q" E* `3 U6 N            <option value="Orange1">Orange</option>% p! L: V: ]; c' z. o
            <option value="Apple2">Apple</option>7 J+ x' z/ U2 b2 t
            <option value="Banana3">Banana</option>
9 S: y, h6 }, _2 I& Q% T        </select>
  y' [. f& E$ [, j& q        <br>, j. d0 `9 `6 c$ ^
        <input type="button" value="disable">3 m9 @) h1 A. o/ S. D7 Z
        <input type="button" value="Able">; T0 x  z. ^% N4 L, [0 B" T. Y3 r9 Z
        <input type="button" value="getValues">4 \: N) S& M7 w( r! W6 v6 j' c0 b
        <input type="button" value="editValues">
% Z& n1 L" U% |* U& A        <input type="button" value="addValues">  V8 Q8 J. M6 f' k
        <input type="button" value="removeValues">( ?  N# p4 C# A5 G, n' p
        <br>
" e& i; {2 v6 c6 m2 g1 U
+ e% y" u  T5 m) j9 \( J    </form>: v: p8 p* T* X! n
6 t7 y0 C3 L) V7 q; I" e7 U
    <p id="demoInput"></p>
2 \; a/ k, }( z, |; T$ P
- g) U9 c7 O. @# m" @, P1 J7 l# y4 I/ l; d5 L% Q
    <script>
/ A5 [' t! H- y4 R  d        function disableFunc() {) G2 g0 o8 A, r' w4 E& H( L
            document.getElementById('mySelect').disabled = true* L( h) L9 ]* {' S0 r- f8 U
        }6 H0 @  b7 u7 M# E' O6 E
        function ableFunc() {
& u! v+ V; U" |! E( p* m            document.getElementById('mySelect').disabled = false
' h( k# s4 a- V0 ~$ h  _* R        }, o7 u. r' [  @* e2 O5 t
        function getValues() {8 d7 Y8 f7 w# O8 l9 k* E- J
            var text = '<ul>'
7 p' @# t& I. L' _5 Q. `6 W5 ?, e            var x = document.getElementById('mySelect')
& Y3 c" F$ n' ?0 e! A' B% d            for (var i = 0; i < x.length; i++) {& Q. u7 A, E1 V6 s* W" n+ r
                text += '<li>' + x.text + '</li>'
, m+ s$ T2 E. L3 q, `. S            }
' O- c' j2 j, M: H% ]- ~. t            text += '</ul>'0 {* U) K7 M5 y& r$ I6 V5 {
            document.getElementById('demoInput').innerHTML = text; Z9 o$ Q# Y( v* H+ V
        }  `# h# `2 v% T8 m5 t, i; ^

$ r/ S! V" C" N$ R% E1 X        function editValue() {
* S8 H0 ?0 z1 {+ g            var mySelected = document.getElementById('mySelect')7 _/ y8 V9 ]& V8 C* e2 p- D1 d
            var selectedIndex = mySelected.selectedIndex
! x% @4 E2 g2 @$ x$ v9 H            mySelected[selectedIndex].text = document.getElementById('inputChange').value+ z; x, p& e9 M" {2 t$ H+ K
        }) {( V2 Z2 y+ {1 S. s1 ^
) a+ _8 C; c) [9 g. k
        function removeValue() {- T) r, Q( H' K# q
            var myselect = document.getElementById('mySelect')
/ y- a' y0 g! }            var selectedIndex = myselect.selectedIndex
. H# Y* b: a; k# T            myselect.remove(selectedIndex)  F8 V5 k1 y1 Q2 ^, g5 m1 Y
        }6 V( n  m+ O% _1 c6 V% S: S
        function addValue() {: R5 N; X$ }' \1 d6 E! m
            var myselect = document.getElementById('mySelect')2 X3 V7 ?& v- ~1 C8 |9 k
            var addvalue = document.getElementById('inputChange').value
' S9 c" t" b. S+ R) @1 i7 R$ X# o            myselect.options.add(new Option(addvalue,"value"))- k4 B5 n  P' X" v8 F
        }. T  i3 ]/ \( s5 q2 \
    </script>
) I7 C2 r8 x( E) k</body>
+ I7 }$ {$ r5 u6 e9 [( u& B# l8 t, {0 v( O  s. W- o
</html>[/mw_shl_code]
% y7 L4 @+ U# {7 C, S
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了