在一个onchange中有2个功能

时间:2015-04-15 17:18:39

标签: javascript php

如何在onchange函数中添加return confirm?这是希望我想添加退货确认('你确定吗?');

<select name='<?php echo "sel".$a; ?>' onchange='this.form.submit()' style='width: 150px'>

1 个答案:

答案 0 :(得分:3)

创建一个javascript函数:

<script type="text/javascript">
    function submitForm(form){
        if(confirm("Are you sure?")){
            form.submit()
        }
        else{
            location.reload()
        }

    }
</script>

然后将您的HTML调整为:

<select name='<?php echo "sel".$a; ?>' onchange='submitForm(this.form)' style='width: 150px'>