javascript 创建一个弹出确认消息按钮href - Flask Jinja

iswrvxsc  于 2023-02-11  发布在  Java
关注(0)|答案(1)|浏览(119)

将JS重构为Flask

如何重构flask和js的部分,只使用flask函数来完成所有这些工作。

flask

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

flask 按钮

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

JS脚本

<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>

简单视图

<a> <input> <confirm>
hts6caw3

hts6caw31#

该解决方案

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

按钮样式
备选案文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>

备选案文2

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

相关问题