JavaScript confirm cancel button not stopping JavaScript

前端 未结 7 1539
天涯浪人
天涯浪人 2020-12-24 15:27

I have a delete button that is tied to some comments on a page i have. When you click the delete button i am trying to get a confirm dialog box to pop up asking if you are

7条回答
  •  盖世英雄少女心
    2020-12-24 16:13

    Maybe it's because you set the type=submit in the form that contains the javascript.

    You should set it to button or image or whatever if you don't want to be submitted if clicked cancel

    example of javascript prompt:

    function javascript_prompt(){
        var name = prompt("Tell me your name.", "");
        if (name != "" && name != null){
            document.form_name.new_name.value = name;
            document.form_name.submit();
        }else{
            return false;
        }
    }
    

提交回复
热议问题