亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何通過js如何打開input?

如何通過js如何打開input?

牛魔王的故事 2019-03-15 19:15:28
一個按鈕一個input<button>Upload</button><input type="file" multiple>點擊input會彈出上傳文件窗口但是我想要的效果:點擊button會彈出input上傳窗口,這個用js該怎么實現呢?
查看完整描述

7 回答

?
慕容708150

TA貢獻1831條經驗 獲得超4個贊

$("button").on("click",function () {

        $("input").click()

    })


查看完整回答
反對 回復 2019-04-10
?
夢里花落0921

TA貢獻1772條經驗 獲得超6個贊

input opactity設置為0后絕對定為到button上面試試


查看完整回答
反對 回復 2019-04-10
?
蝴蝶不菲

TA貢獻1810條經驗 獲得超4個贊

定制文件輸入框(input,type,file)樣式

<!DOCTYPE HTML>

<html>

<head>

    <meta charset="utf-8">

    <title>三十客-定制文件輸入框(input,type,file)樣式</title>

    <style>

        .file-wrapper {

            position: relative;

            width: 225px;

        }

        .file-label {

            display: block;

            padding: 14px 20px;

            background: #39D2B4;

            color: #fff;

            font-size: 1em;

            text-align: center;

            transition: all .4s;

            cursor: pointer;

        }

        .input-file {

            position: absolute;

            top: 0; left: 0;

            width: 225px;

            opacity: 0;

            padding: 14px 0;

            cursor: pointer;

        }

        .input-file:hover + .file-label,

        .input-file:focus + .file-label {

            background: #34495E;

            color: #39D2B4;

        }

        form {

            padding: 1rem 0 0 1rem;

        }

    </style>

</head>

<body>

<h2>點擊按鈕查看演示效果</h2>    

<form action="#">

    <div class="file-wrapper">

        <input class="input-file" id="my-file" type="file">

        <label tabindex="0" for="my-file" class="file-label">選擇一個文件...</label>

    </div>

</form>

</body>

</html>


查看完整回答
反對 回復 2019-04-10
?
慕妹3242003

TA貢獻1824條經驗 獲得超6個贊

button,input 自己通過id 或者 tag 獲取,大致寫法如下


button.onclick=function(){

    input.onclick();

}


查看完整回答
反對 回復 2019-04-10
  • 7 回答
  • 0 關注
  • 764 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號