javascript - 从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">×</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;
我怎么解决这个问题 ??
解决方案
javascript是错误的,代码应该是这样的,
function AddItem(){
var ItemDesc = document.getElementById("orangeForm-company").value;
var ItemType = document.getElementById("sel1").value;
SearchInDataBase(ItemDesc,ItemType);
}
推荐阅读
- python - 如何在 Pandas 数据透视表中聚合数据?
- javascript - 延迟显示 StencilJs 组件
- tailwind-css - Tailwind 断点类不基于断点呈现
- vba - 命令或操作“TransferText”现在不可用
- php - 如何将php变量传递给函数add_cart_item_data以修改wordpress woocommerce中的产品价格
- javascript - JS 和 3d css 破碎的 3d 运动
- puppet - 如何在 puppet 中实现虚拟层次数据,或者,如何从每台机器上的用户选择中抽象层次用户定义?
- azure - Azure 应用配置推送任务 - 如何使用此任务在 azure 应用配置中部署密钥保管库参考值?
- python - Geemap 包 - PCA 分析
- xml - 如何为 mp4box 创建 CENC 加密的 xml 文件?