0

我有这样的表格:

<select>
    <option value="page1.html" class="confirm">Page 1</option>
    <option value="page2.html" class="confirm">Page 2</option>
    <option value="page3.html">Page 3</option>
</select>

我想在转到第 1 页或第 2 页之前使用 SimpleModal 显示确认信息,但如果选择了第 3 页则不会。第 1 页和第 2 页的确认消息应该相同。我对如何执行语法有点困惑。

4

1 回答 1

1

SimpleModal Confirm Demo中的 JavaScript 为例,您可以执行以下操作:

    // replace 'form' with your form selector
$('form').submit(function (e) {

            // replace 'option:selected' with a more specific selector
    var opt = $('option:selected');

            // if the selected option has a class of confirm, show the dialog
    if (opt.hasClass('confirm')) {

        e.preventDefault();

        // example of calling the confirm function
        // you must use a callback function to perform the "yes" action
        confirm("Continue to the SimpleModal Project page?", function () {
            window.location.href = 'http://www.ericmmartin.com/projects/simplemodal/';
        });
    }
});
于 2011-03-03T22:28:39.703 回答