s***@163.com
s***@163.com
  • 发布:2019-09-02 18:22
  • 更新:2019-09-02 18:22
  • 阅读:2316

请教document.getElementById(id).value为空的问题

分类:uni-app

我的程序中有很多input组件,input输入数字后,进行计算,前段时间通过学习,使用“event.target.value”获得input的输入值已经掌握了,但是现在要输入的值比较多,这么做太麻烦了,想实时监控输入情况自动计算,但使用document.getElementById(id).value,无论“BDZJ”怎么输数字,获取数据是空的,查了三四天资料,还没搞清楚。请大神指点一二。

<template>  
    <view>  
        <t-table border="1" border-color="#aaa" width="99%">  
            <view class="title">除尘器尺寸重量估算</view>  
            <t-tr font-size="15" color="#3f3f3f">  
                <t-th style="flex:0.17; font-weight: Normal;">  
                    <pre>布袋直径<br>(mm)</pre>  
                </t-th>  
                <t-th style="flex:0.17; font-weight: Normal;">  
                    <pre>布袋长度<br>(m)</pre>  
                </t-th>  
                <t-th style="flex:0.18; font-weight: Normal;">  
                    <pre>过滤风速<br>(m/s)</pre>  
                </t-th>  
                <t-th style="flex:0.16; font-weight: Normal;"><pre>箱体个数</pre></t-th>  
                <t-th style="flex:0.16; font-weight: Normal;"><pre>单个箱体脉冲阀数</pre></t-th>  
                <t-th style="flex:0.16; font-weight: Normal;"><pre>单根喷管喷嘴数量</pre></t-th>  
            </t-tr>  
            <t-tr font-size="15" color="#3f3f3f">  
                <t-th style="flex:0.17;"><input type="digit" maxlength="5" id="BDZJ_id" @input="CS_Input" /></t-th>  
                <t-th style="flex:0.17;"><input type="digit" maxlength="5" id="BDCD_id" @input="CS_Input" /></t-th>  
                <t-th style="flex:0.18;"><input type="digit" maxlength="5" id="GLFS_id" @input="CS_Input" /></t-th>  
                <t-th style="flex:0.16;"><input type="digit" maxlength="5" id="XTGS_id" @input="CS_Input" /></t-th>  
                <t-th style="flex:0.16;"><input type="digit" maxlength="5" id="DXFS_id" @input="CS_Input" /></t-th>  
                <t-th style="flex:0.16;"><input type="digit" maxlength="5" id="DGZS_id" @input="CS_Input" /></t-th>  
            </t-tr>  
            <t-tr font-size="15" color="#3f3f3f">  
                <t-th style="flex:0.2; font-weight: Normal;"><pre>布袋条数</pre></t-th>  
                <t-th style="flex:0.2; font-weight: Normal;">  
                    <pre>过滤面积<br>(m²)</pre>  
                </t-th>  
                <t-th style="flex:0.3; font-weight: Normal;">  
                    <pre>处理风量<br>(m³/h)</pre>  
                </t-th>  
                <t-th style="flex:0.15; font-weight: Normal;">  
                    <pre>进口风速<br>(m/s)</pre>  
                </t-th>  
                <t-th style="flex:0.15; font-weight: Normal;">  
                    <pre>进口管径<br>(m)</pre>  
                </t-th>  
            </t-tr>  
            <t-tr font-size="15" color="#3f3f3f">  
                <t-th style="flex:0.2;word-wrap: break-word;word-break: break-all;">  
                    <text style="color: red;font-size: 16px;">{{ BDTS }}</text>  
                </t-th>  
                <t-th style="flex:0.2;word-wrap: break-word;word-break: break-all;">  
                    <text style="color: red;font-size: 16px;">{{ GLMJ }}</text>  
                </t-th>  
                <t-th style="flex:0.3;word-wrap: break-word;word-break: break-all;">  
                    <text style="color: red;font-size: 16px;">{{ CLFL }}</text>  
                </t-th>  
                <t-th style="flex:0.15;"><input type="digit" maxlength="5" id="JKFS_id" placeholder="16" @input="CS_Input" /></t-th>  
                <t-th style="flex:0.15;word-wrap: break-word;word-break: break-all;">  
                    <text style="color: red;font-size: 16px;">{{ JKGJ }}</text>  
                </t-th>  
            </t-tr>  
        </t-table>  
    </view>  
</template>  

<script>  
//……部分代码省略  
    methods: {  
        CS_Input: function() {  
            this.BDZJ = document.getElementById("BDZJ_id").value;   
            this.BDCD = document.getElementById("BDCD_id").value;  
            this.GLFS = document.getElementById("GLFS_id").value;  
            this.XTGS = document.getElementById("XTGS_id").value;  
            this.DXFS = document.getElementById("DXFS_id").value;  
            this.DGZS = document.getElementById("DGZS_id").value;  
            this.BDTS = this.BDZJ;   //测试是否获取了输入数据  
            this.GLMJ = accMul(accMul(accMul(accMul(Math.PI, 0.001), parseFloat(this.BDZJ)), parseFloat(this.BDCD)), parseFloat(this.BDTS));  
            this.CLFL = accMul(accMul(parseFloat(this.GLMJ), parseFloat(this.GLFS)), 60);  
        },  

        onNavigationBarButtonTap(e) {  
            uni.navigateTo({  
                url: '/pages/index/index'  
            });  
        }  
    }  
};  
</script>
2019-09-02 18:22 负责人:无 分享
已邀请:

该问题目前已经被锁定, 无法添加新回复