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>

SimpleModalを使用して、ページ1またはページ2に移動する前に確認を表示したいのですが、ページ3が選択されている場合は表示しません。確認メッセージは、ページ1とページ2で同じである必要があります。構文の実行方法について少し混乱しています。

4

1 に答える 1

1

例としてSimpleModalConfirmDemoの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 に答える