【问题标题】:Javascript Noob wants to ask about onclick eventsJavascript Noob 想问关于 onclick 事件
【发布时间】:2012-01-05 10:44:22
【问题描述】:

我目前正在为一个 django 项目编写模板,并且是一个完整的 javascript 初学者。我有问题的模板部分如下所示:

<form action='/gh/' method='GET'>
    <label>Synchronisation:</label>
    <input type='image' src='/site_media/images/sync.png' height='27', width='27' onclick="return confirm('Sind Sie sicher, dass Sie Synchronisieren wollen?');" alt="Synchronisation"></input>
  </form>

现在,如果我单击图像 (sync.png),我会看到一个确认框,我可以在其中选择“确定”或“取消”。现在,如果单击确定,我想显示图像。这个要怎么写?

【问题讨论】:

  • 仅供参考,问题标题应该是您问题的摘要,而不是关于 javascript 的问题。我们知道,从 1. 你在 StackOverflow 上,2. javascript 标签。 :)

标签: javascript django forms templates


【解决方案1】:

您需要的是一个确认框:因此您必须执行以下操作: 创建一个在点击时调用的函数:

function button_on_click(){
    if(confirm('Sind Sie sicher, dass Sie Synchronisieren wollen?'))
    {
         //when ok is pushed do somehting here
         var element = document.getElementById('image_to_show'); 
         element.css.display = 'block';
    }
    else
    {
         //this will handle the cancel event
    }
}

这应该可以解决问题。所以只需在元素的 onclick 属性上添加 button_on_click()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-20
    相关资源
    最近更新 更多