如何访问(Div)ID到javascript

时间:2019-05-30 13:32:45

标签: javascript

You can see the image 我想在我的Java脚本中访问DIV ID。我要怎么走

实际上我有2个上传文件,一个是上传图像,一个是拖放图像,我希望在提交表单时一个是强制性的,所以我该怎么做?

我的HTML页面

<div class="form-group" id="attachFilesDrag">   
        <div class="col-lg-12 col-xs-12"><p class="sec_text_1">{required}Attachment(s)</p></div>
            <div class="placeholder col-lg-7 col-md-7 col-sm-7 col-xs-12" id="attachFiles">
                <div class="js_prev_block">
                     <span class="class_files">
                    <input type="file" name="attach[]" class="add_files form-control-attachment"  /> <!-- id="attach"-->
                     </span>
                     <a href="#" onclick="return appendUploadFiles(this);" class="v_middle">
                         <i class="icon-plus"></i>
                     </a>
                     <a href="#" onclick="return removeUploadFiles(this);" class="v_middle">
                         <i class="icon-remove"></i>
                     </a>
                </div>
                <div class="js_next_block"></div>
            </div>


                <div id="orDiv" class="col-lg-1 col-md-1 col-sm-1 col-xs-11 vcenter marginor" style="margin-top:10px;">OR</div>
                <div class="dragDropAdd col-md-3 col-sm-3 col-xs-11" id="dragAndDropHandler" data-value='2'>Drag & Drop Files Here</div>

         </div>       

提交时

<input type="submit" value="Save" name="val[addNotification]" class="notranslate btn-md btn-primary" id="submit" />
                        <input type="submit" value="Submit" name="val[finaladdNotification]" class="notranslate btn-md btn-success" id="submit" />

我想像这样访问以验证我在JavaScript中的工作方式 。 我的JS文件

 if(document.getElementById('attach').value == '' || (document.getElementById("dragAndDropHandler").getAttribute("data-value")) != '2')
      {
         alert('You must upload minimum one image');
         document.getElementById('attach').focus();
         flag="0";
         return false;
      }

0 个答案:

没有答案