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

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

[复制链接]

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

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

admin 楼主

2019-11-4 20:15:32

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

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

x

7 c0 x# {/ Y' u! g0 Z+ r
* \: n! n8 v; K9 NJS 操作 Select相关功能测试9 G" Z5 \9 O4 i* f, j
3 P2 C: T0 U7 y
[mw_shl_code=html,true]<html lang="en">
# C% [. J# I9 d8 R" F. q) n1 \. T, I& Z9 K# b) n7 s+ Y
<head>
7 O% n5 ?9 }3 b+ f' u) c    <meta charset="UTF-8">
. p; x0 B0 h" A6 o4 z$ z    <meta name="viewport" content="width=device-width, initial-scale=1.0">' |; c, j; w% I( P: V
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
1 `# |( u3 G* i5 q    <title>Document</title>' Y7 q* W" s" [) [
    <style>
+ P2 p$ ^+ r6 T0 I" W. c        * {
9 q# q) z8 B" l2 T            font-size: 10px;
) A9 o7 P! G" v            line-height: 24px;( t' \; [. z" e2 i6 U
        }: O, \' j) z* h3 w% W! ]4 k
    </style>. `9 L: s3 a7 ~- M
</head>( l7 x7 v1 x' D- O3 s- F

7 A- F% \" T9 N. m5 a5 @<body>. S  W! B! o. _$ L) O. {7 Y. a
    //this is for the select test# o; l7 b" ~" \* ^: W
    <form id='myForm' action="submit" method="GET">& ?8 M# K1 W9 O$ U) I8 M
        <input type="text" id="inpuTChange" />) {8 k; r% v0 H
        <select name="selectFruits" id="mySelect">
& }( h5 N1 ]9 S5 h4 }; j1 C4 k; l! O( V            <option value="Orange1">Orange</option>  e- |0 l3 b/ Y, `# f
            <option value="Apple2">Apple</option>
2 C( a9 n; \7 v! n& @8 c0 O" W9 ^            <option value="Banana3">Banana</option>
) u% @0 S8 T6 K! Z" y        </select>
3 Z. W$ q! f( o1 m! P        <br>  m& `7 o' g, F# W& p
        <input type="button" value="disable">' Z2 E( G9 u. a
        <input type="button" value="Able">7 R4 _1 H' q0 W# o! E. C4 s( d
        <input type="button" value="getValues">
% V4 Z& e, X3 U: ?9 z        <input type="button" value="editValues">
# a7 V9 N5 e* b7 o: W        <input type="button" value="addValues">+ A: _3 [: {8 I5 Z7 l
        <input type="button" value="removeValues">
, y5 i. A3 H/ K, G$ q4 V" L        <br>0 l  s) j  A- w

8 I, W* e- Q& Z% C* A: n! Y: L    </form>7 k% }( v3 B2 o7 l0 f% R  i# b- l

4 `% g2 n  |, U! I0 d. ]5 @0 `    <p id="demoInput"></p>
9 e6 b9 ?; L( a% j+ l+ S; K. p( O7 g& }4 A

& B1 _; W& g& w0 c" h    <script>
) u1 i+ v  K" I5 d        function disableFunc() {
) o/ B; }1 g/ Q; `0 k            document.getElementById('mySelect').disabled = true
! w/ n: o1 l* T# h1 B5 S        }* m$ P  o$ k+ x) F% h: y
        function ableFunc() {1 B0 ~- b& B. C# \) E6 T
            document.getElementById('mySelect').disabled = false& G  n: [2 h, y! W# Z: j0 C
        }
2 L' r5 v  o& ~1 T0 `        function getValues() {! p9 ^" N2 O8 F: ]3 r
            var text = '<ul>'
+ B4 b" ~, a6 }8 `6 c& \: y            var x = document.getElementById('mySelect')' w' d" e  y( N/ {; P9 q
            for (var i = 0; i < x.length; i++) {
& r% X: ]7 ^& J2 n1 `9 d                text += '<li>' + x.text + '</li>'
0 V# g3 ?+ |6 w+ k6 V            }
$ L" k, \" x% |' N% l            text += '</ul>'" p4 Y( B0 W2 {6 j
            document.getElementById('demoInput').innerHTML = text
9 P: z" [- S" x' v        }. Z# e8 V# }5 E  u* I* G- o5 I* i( K

; @) F% d+ D' W# W! b: g        function editValue() {
: l) C0 [7 r9 I- N, T5 o            var mySelected = document.getElementById('mySelect')
, M: I$ c$ l& P3 v$ D. e3 d% q" s            var selectedIndex = mySelected.selectedIndex
+ |7 Y& w! O) `& r3 P  c6 m            mySelected[selectedIndex].text = document.getElementById('inputChange').value9 _3 A! r: o$ A  t2 B& T
        }
7 u- L9 V' Q3 _2 q) D& b, H+ r: W$ |% Q
0 [! Y$ Y( ?' y        function removeValue() {* T$ m" O6 q/ P$ S
            var myselect = document.getElementById('mySelect'); a, `5 m# j$ s7 P' l3 y' U
            var selectedIndex = myselect.selectedIndex
3 i: x$ d/ W- X            myselect.remove(selectedIndex)
- N& G6 r5 t2 f) e2 o- p+ G        }8 V2 ?5 J) b, D! o  p
        function addValue() {
; z) f, u# F/ o# i' u$ Q# C0 N$ z            var myselect = document.getElementById('mySelect')- f' L6 a6 F, \0 s# i6 Y# ?& a
            var addvalue = document.getElementById('inputChange').value8 [4 C* X! p+ u. w2 ~! X; _8 t
            myselect.options.add(new Option(addvalue,"value"))5 X' Q" t! S4 \8 @# k" C
        }; D4 A' `6 ~  j7 V
    </script>
( ?% d* L3 W. V% @3 ]7 o</body>/ ~6 W6 X; g* B) Y7 g

& w- J1 I: _5 L- d</html>[/mw_shl_code]7 \: K! j- r5 e% j* |9 q
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了