简体   繁体   中英

Flask JavaScript js Jinja- Create a pop up confirmation message button href

Simplify all of this

<a> <input> <button> <confirm>

Using Flask

<a href="{{ url_for('products.delete', id=product.cod) }}" >Delete</a> 

Flask button

<input type="button" value="Delete">

JS script

<button onclick="myFunction()">Try it</button>

<p id="demo"></p>

<script>
function myFunction() {
  let text;
  if (confirm("Press a button!") == true) {
    text = "You pressed OK!";
  } else {
    text = "You canceled!";
  }
  document.getElementById("demo").innerHTML = text;
}

</script>

I need a function that do all of this.

The solution

<a href="{{ url_for('productos.delete', id=producto.codprod) }}" onclick="return confirm('Are you sure?')">Delete</a>

and the button style

option 1

<a
  href="{{ url_for('productos.delete', id=producto.codprod) }}"
  onclick="return confirm('Are you sure?')"
  type="button"
  style="text-decoration: none;
    min-width: 100px; 
    max-height: 30px; 
    background-color: #224a64; 
    color: #fff;
    text-align: center; 
    border-radius: 6px; 
    cursor: pointer; 
    right: 0px;
  "
  >Eliminar
  </a>

option 2

<a href="{{ url_for('productos.delete', id=producto.codprod) }}" onclick="return confirm('Are you sure?')"><input type="button" value="Eliminar"></a>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM