Onclick取消应用程序事件

时间:2017-05-29 01:04:45

标签: javascript

js的新手...需要你的帮助。我想创建一个取消按钮,在单击取消按钮时取消在线表单会话。在取消会话之前,我希望在取消应用程序会话之前出现通知弹出窗口(onclick事件),要求用户进行确认。请参阅以下代码:

 <form>
   <div class="form-group">
       <label for="Product">Product</label>
       <input type="text" name="product" id="product" required="required" value="">
   </div>
   <div class="form-group">
       <label for="Product">Product1</label>
       <input type="text" name="product1" id="product1" required="required" value="">
   </div>
   <div class="form-group">
       <label for="Product">Product2</label>
       <input type="text" name="product2" id="product2" required="required" value="">
   </div>
  <div>
  <button name="submit">Add Product</span></button>&nbsp;&nbsp;<a href="http://www.google.com" onclick="">**Cancel**</a>           
  </div>


 </form>

3 个答案:

答案 0 :(得分:0)

tshark -r "semAtaques.pcap" -Tfields -e frame.time_epoch -e tcp.window_size_value -e ip.dst -Y "ip.dst == 192.168.91.5" -e tcp.port eq 80 >> winTime_10Abril_SemAtaques.txt

答案 1 :(得分:0)

如果不编辑表单,请选择元素,将“click”事件侦听器附加到要侦听的元素,在这种情况下,“取消”标记。点击注册后,使用确认框确认。如果Ok抓取表单并重置它并重定向用户。否则,做点别的事。

    <form id='form1'> 
<div class="form-group">
 <label for="Product">Product</label> <input type="text" name="product" id="product" required="required" value=""> </div> 
<div class="form-group"> 
<label for="Product">Product1</label> <input type="text" name="product1" id="product1" required="required" value=""> </div>
 <div class="form-group"> <label for="Product">Product2</label> <input type="text" name="product2" id="product2" required="required" value=""> </div>
 <div> 
<button name="submit">Add Product</span></button>&nbsp;&nbsp;
<a href="javascript:void(0)" onclick="reset('form1')">**Cancel**</a> </div> 
</form>
    <script>
    function(id){
       if(confirm("do you want to cancel?")){
           $("#"+id)[0].reset();
        }
    }
    </script

>
// grab your cancel anchor tag
var anchor = document.querySelector("[href='http://www.google.com']");
// grab your form
var form = document.getElementsByTagName('form')[0];
// add an event listener on to your cancle anchor tag
anchor.addEventListener('click',clicked =>{ 
// assign your confirm to varable yes
var yes = confirm('are you sure you want to cancle');
if(yes===true){
// if they confirm their departure reset the form 
form.reset();
//alert them of a successfull form reset and inform them of the reroute
alert('the form has been reset you are going to be rerouted to google');
// use location to reroute to a different domain
//window.location.href("http://www.google.com")
// or within the current domain using a relative path
// window.location.href = '../' one level up
// winsow.location.href = '/path' relative to a domain
}else{
alert('you decided to cancle');  
// do nothing 
}
});

答案 2 :(得分:0)

首先你需要点击确认功能,在继续之前会要求用户批准

item_boxes.map( (item_box,index) =>  {
    var id = item_box.getAttribute("data-id")
    item_box.find... .text //if you actually need to do something with the index
})
相关问题