javascript - 微信小程序·如何监听·软键盘回车键搜索事件
伊谢尔伦
伊谢尔伦 2017-04-11 11:00:35
0
3
1194


点击软键盘回车键的时候想要触发微信小程序的提交表单事件,如何处理?

<form bindsubmit="searchSubmit" action="">
    <view class="weui-search-bar">
        <view class="weui-search-bar__form">
            <view class="weui-search-bar__box">
                <icon class="weui-icon-search_in-box" type="search" size="14"></icon>
                <input type="text" class="weui-search-bar__input" placeholder="搜索" value="{{inputVal}}" focus="{{inputShowed}}" bindinput="inputTyping" />
                <view class="weui-icon-clear" wx:if="{{inputVal.length > 0}}" bindtap="clearInput">
                    <icon type="clear" size="14"></icon>
                </view>
            </view>
            <label class="weui-search-bar__label" hidden="{{inputShowed}}" bindtap="showInput">
                <icon class="weui-icon-search" type="search" size="14"></icon>
                <view class="weui-search-bar__text">搜索</view>
            </label>
        </view>
        <view class="weui-search-bar__cancel-btn" hidden="{{!inputShowed}}" bindtap="hideInput">取消</view>
    </view>
</form>
searchSubmit: function(e) {
        console.info(12);
        console.info('form发生了submit事件,携带数据为:', e.detail.value)
    }"
伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

reply all(3)
洪涛

看官方文档https://mp.weixin.qq.com/debu...

里面有个bindconfirm属性。

Peter_Zhu

请教一下 ,你的标签是怎么实现的啊?

小葫芦
//监听回车可以触发登录按钮
    document.onkeydown = keyDownSearch;
    function keyDownSearch(e) {
        // 兼容FF和IE和Opera    
        var theEvent = e || window.event;
        var code = theEvent.keyCode || theEvent.which || theEvent.charCode;
        // 13 代表 回车键
        if (code == 13) {
            // 要执行的函数 或者点击事件
            $(".login-button").click();
            return false;
        }
        return true;
    }
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template