JavaScript删除确认框

时间:2013-03-08 09:10:00

标签: javascript

我的功能是这样的:

function delete(type, id){
    if(id){
        window.location.href = '/site/'+type+'/delete/'+id;
    }
}

我这样称呼它:

onclick="delete('position', <?php echo $key;?>)

我应该在函数中的哪个位置放置确认选项?

2 个答案:

答案 0 :(得分:2)

试试这个:

function deleteIt(type, id)
{
    if(id && confirm('Are you sure you want to delete?'))
    {
        window.location.href = '/site/'+type+'/delete/'+id;
    }
}

答案 1 :(得分:0)

function delete(type, id)
{
    if(id && (confirm('Are you sure you want to delete?')))
    {
        window.location.href = '/site/'+type+'/delete/'+id;
    }
}