帖子
帖子
用户
博客
课程
显示全部楼层
4
帖子
0
勋章
21
Y币

[其他] 安卓可以,苹果用不了 document.getElementById('TAG ID VALUE').value ?

[复制链接]
发表于 2021-4-19 23:15:16
本帖最后由 小斧头 于 2021-4-21 00:56 编辑

安卓手机运行以下代码没有问题,可是在iPhone就说 !usernameValue的结果是 false
请问iPhone 不可以用document.getElementById('username').value吗?
全部代码如下

<template>
    <view class="main">
        <navigationBar title="会员注册"></navigationBar>
        <scroll-view class="scrollView" scroll-y='true'>
            <view class="container">
                <input id="username" class="input" type="text" placeholder="用户名"/>
                <text class="btn" onclick={this.fnRegister}>"注册"</text>
            </view>
        </scroll-view>
    </view>
</template>
<script>
import navigationBar from "../../components/navigationBar.stml"
export default {
    name: 'register',
    data() {
        return {
        }
    },
    methods: {
        apiready() {
            document.getElementById('username').focus();
        },
        fnRegister() {
                this.toast(document.getElementById('username').value);
        },
        toast(msg) {
            api.toast({
                msg: msg,
                location: 'middle',
                global: true
            });
        }
    }
}
</script>
<style>
    .main {
        width: 100%;
        height: 100%;
    }
    .scrollView {
        flex: 1;
    }
    .container {
        padding: 20px;
    }
    .input {
        width: 100%;
        height: 40px;
        margin-bottom: 30px;
        border: none;
        border-bottom: 1px solid #ddd;
    }
    .btn {
        height: 50px;
        background-color: #0268c8;
        line-height: 50px;
        color: #fff;
        font-size: 24px;
        text-align: center;
        border-radius: 8px;
    }


    .btn:active {
        opacity: 0.8;
    }
</style>





380
帖子
4
勋章
6
Y币
可以
4
帖子
0
勋章
21
Y币
本帖最后由 小斧头 于 2021-4-20 21:35 编辑

fnRegister() {
this.toast(document.getElementById('username').value);
}

在苹果手机上显示空白,安卓手机上显示打入的value。
4
帖子
0
勋章
21
Y币

如果直接用一下的代码
<input id="username" class="input" type="text" value="test"/>
的确可以拿到 test
可是
如果
<input id="username" class="input" type="text"/>
然后自己打入却无法返回value
4
帖子
0
勋章
21
Y币
本帖最后由 小斧头 于 2021-4-21 02:05 编辑

是不是 iOS不支持使用 <template></template> 和 .stml
因为我换成 .html + 引用api.js + 纯javascript
结果是可以拿到value的

现在已解决,用onBlur event来传递新的value。
可是有没有更好的方式,直接在iOS上读取新的value?
28
帖子
1
勋章
1万+
Y币
现在重新编译再试试。
4
帖子
0
勋章
21
Y币
技术咨询-Kenny 发表于 2021-4-21 10:22
现在重新编译再试试。

你好,
我用的是 真机同步 和 iOS自定义loader
这算是重新编译了吗?

刚真机同步一次,也是不行
现在用oninput event,结果来说,还是不错的
380
帖子
4
勋章
6
Y币
小斧头 发表于 2021-4-21 10:38
你好,
我用的是 真机同步 和 iOS自定义loader
这算是重新编译了吗?

重新编译自定义loader
4
帖子
0
勋章
21
Y币
技术支持-F 发表于 2021-4-21 10:40
重新编译自定义loader

重新编译自定义loader后,真的可以了
谢谢。
76
帖子
0
勋章
2613
Y币
好的,那结贴了,有问题再及时发帖咨询
您需要登录后才可以回帖 登录

本版积分规则