PLM之家PLMHome-工业软件践行者

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

[复制链接]

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

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

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

x
) J! F( _1 N) E( z, n  [) z  N

, s$ h8 E3 X5 j$ _JS 操作 Select相关功能测试
1 D8 v7 y5 r) \
/ }& l  [# q* [[mw_shl_code=html,true]<html lang="en">
0 L  s: |" n3 a+ d4 A  t; X# ~" x2 K
<head>
6 s) R1 G$ F: Q. r- a2 A& P    <meta charset="UTF-8">
5 F  d  ^% z% q0 a$ P9 d) n6 C# \    <meta name="viewport" content="width=device-width, initial-scale=1.0">
" x& h. K. E, V8 B2 c    <meta http-equiv="X-UA-Compatible" content="ie=edge">
- Z( w& {9 m! |    <title>Document</title>
+ `* I5 E# b. m! g    <style>
7 }& u8 ?4 j8 \" \2 w        * {# i$ O' A" @6 g! U/ O
            font-size: 10px;
3 R! g; Z1 _- j3 u3 i& Q            line-height: 24px;2 U5 z8 q9 \- D/ Q3 K( G1 }; i
        }
$ D$ V0 P5 i" U; t+ X    </style>9 {' X% G! ^7 O# x8 W- O7 X
</head>
9 R) h8 g. L' `* X* S* [0 n: Q, d1 f+ i) H# B
<body>
1 ~" L( d% J! g+ a1 F% W$ ~    //this is for the select test# T" y) V' L' A( S9 n  @3 O; F9 T) S
    <form id='myForm' action="submit" method="GET">
! E+ ?9 C6 @" G2 S        <input type="text" id="inpuTChange" />( t8 ]! S  N# q) j( G
        <select name="selectFruits" id="mySelect">
+ B8 D) e6 b8 @' E0 b- Y9 ^            <option value="Orange1">Orange</option>
) m5 V* }9 j7 D% |5 x3 p            <option value="Apple2">Apple</option>
  ]! W; \; ]5 q' V. `& y5 B            <option value="Banana3">Banana</option>
% {8 F0 v. o& t        </select>. K7 G  u1 f3 q$ F+ n6 p8 k
        <br>2 `( x+ w4 R! b% s' x( y6 j( X
        <input type="button" value="disable">& w; W) m: O0 m, u- y
        <input type="button" value="Able">3 T3 a7 U: w$ D; {
        <input type="button" value="getValues">. n% z  U7 W& m' o7 v5 [9 q7 e3 X$ B
        <input type="button" value="editValues">+ ]5 b3 E; W2 l
        <input type="button" value="addValues"># V( ~6 W* x8 ?. L
        <input type="button" value="removeValues">$ ~" V1 Z9 q- G8 G  K2 J
        <br>( ^2 Y! {! @7 m& H8 w

0 F4 {6 [; s0 j7 [9 }% a    </form># B$ q1 c$ Q# t/ _& Z. c9 \
7 l! t5 B1 C+ }$ Z. V5 _% A0 e" F
    <p id="demoInput"></p>
9 V2 D# k1 `) \8 R1 ?4 z
! s2 _$ ~! H# c! T/ k) K& m6 K$ @4 N
    <script>
1 z/ k! Y- ]: t. \, d5 X: Z: Y        function disableFunc() {+ B4 j- n! c; F' E
            document.getElementById('mySelect').disabled = true
/ Y1 @6 O7 E% _9 ?% T" h: ]- E5 v9 j1 P        }
$ }# v7 t# @7 V9 r        function ableFunc() {
) r7 P/ Z8 r  @+ e( \* j" [            document.getElementById('mySelect').disabled = false
8 s! R. L" k: p0 F+ ?4 E7 _        }
9 K4 W0 g  c! b        function getValues() {7 ?& P& ^/ C" |5 O8 d3 K
            var text = '<ul>'
% W- Z! i9 K: ]$ D            var x = document.getElementById('mySelect')6 ~7 t9 i! o% w# j
            for (var i = 0; i < x.length; i++) {9 W5 \3 D, u4 k% H3 c" @' o5 I. K
                text += '<li>' + x.text + '</li>'
$ x- }* z( P7 p- j, ^            }
: d7 r$ k, M) N0 l; v, a            text += '</ul>'& b4 r/ T6 t- U9 ~) p8 e- T
            document.getElementById('demoInput').innerHTML = text; [9 E. ]7 K  n/ t2 |
        }( v. }! f, v7 a! P- L
/ b; i% ^/ Q( l& q/ G% s2 q
        function editValue() {
7 L4 p0 q  S7 S% T3 F/ n6 L            var mySelected = document.getElementById('mySelect'), \' N( k4 K' @" @+ ]1 l
            var selectedIndex = mySelected.selectedIndex: B( c. ^1 N% m5 i( G" J* e% a
            mySelected[selectedIndex].text = document.getElementById('inputChange').value
+ c5 L) v) Z) M! D        }
5 o0 `5 l. R5 x3 y9 h6 R, o% g' V+ r% k1 q" w1 `
        function removeValue() {7 L% x2 |0 G) g5 \) Y/ F- Q6 g
            var myselect = document.getElementById('mySelect')
! X6 ~2 Z/ G- @$ \. ~            var selectedIndex = myselect.selectedIndex, t# b1 H# ?, n  {9 X  p
            myselect.remove(selectedIndex)' m  D$ X. H' b- i: [3 u
        }
4 r& A/ G- a- r! ?7 V6 \; B% H7 e: E, L        function addValue() {
2 _2 k8 R. `  V$ P' Z7 Z            var myselect = document.getElementById('mySelect')
. f: `; Y4 r' D$ k+ ]( G            var addvalue = document.getElementById('inputChange').value
* I1 t- w1 D+ b+ \            myselect.options.add(new Option(addvalue,"value"))$ }& ^& ]6 v8 u9 d8 x. A
        }
! W) D/ @/ n1 c3 Y    </script>+ V4 `6 B( o/ M& O+ y, g
</body>
, z" M% j+ A% y7 l- r! n2 P; `: X+ r3 l: n& ]) X0 a
</html>[/mw_shl_code]! f5 [! T- L! c# F" o6 k
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了