我目前正在为一个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),我会得到一个确认框,在那里我可以选择Ok或Cancel。现在,如果点击Ok,我想要显示一张图片。我该怎么写呢?
发布于 2011-11-24 16:38:58
您需要的是一个确认框:所以您必须这样做:创建一个函数,以便在单击时调用:
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()即可
https://stackoverflow.com/questions/8254089
复制相似问题