首页 > 解决方案 > 从html中的模型获取数据到文件js

问题描述

我在 html 文件中有一个带有按钮的模型,它指导我在 JS 文件中运行。我的问题是我无法从我的 HTML 代码的模型中获取数据

 <div class="modal fade" id="modalRegisterForm" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
                     aria-hidden="true">
                    <div class="modal-dialog" role="document">
                        <div class="modal-content">
                            <div class="modal-header text-center bg-primary">
                                <h4 class="modal-title w-100 font-weight-bold" style="margin:5px 0 -10px 0;">أسم الصنف</h4>
                                <button type="button" class="close cl" data-dismiss="modal" aria-label="Close">
                                    <span aria-hidden="true">&times;</span>
                                </button>
                            </div>
                            <div class="modal-body mx-3">

                                <div class="md-form text-right">
                                    <label data-error="wrong" data-success="right" for="orangeForm-company">الوصف</label>
                                    <i class="fas fa-pen-fancy prefix blue-text"></i>
                                    <textarea type="text" id="orangeForm-company" name="orangeForm-company" class="form-control validate text-right" placeholder=" إدخال الوصف"></textarea>
                                </div>
                                 <div class="form-group md-form text-right">
                                    <label for="sel1">الفئة</label>
                                    <i class="fas fa-balance-scale prefix grey-text"></i>
                                    <select class="form-control text-right" id="sel1" name="sel1">
                                        <option>خامات</option>
                                        <option class="text-right">تركيبات</option>
                                        <option class="text-right">مكن</option>
                                    </select>
                                </div>
                            </div>
                            <div class="modal-footer d-flex justify-content-center">
                                <button class="btn btn-success" onclick="AddItem()">إضافة</button>
                            </div>
                        </div>
                    </div>
                </div>

虽然我的 JS 代码是

function AddItem(){
var ItemDesc =  getElementById["orangeForm-company"].value;
var ItemType =  getElementById["sel1"].value;
SearchInDataBase(ItemDesc,ItemType); }

此语句中的代码崩溃 getElementById["sel1"].value;

我怎么解决这个问题 ??

标签: javascripthtml

解决方案


javascript是错误的,代码应该是这样的,

function AddItem(){
   var ItemDesc =  document.getElementById("orangeForm-company").value;
   var ItemType =  document.getElementById("sel1").value;
   SearchInDataBase(ItemDesc,ItemType); 
}

推荐阅读