开发者

How can I use SimpleModal to confirm before going to a URL in a select list?

I have a form like this:

<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&开发者_如何转开发gt;
</select>

I want to use SimpleModal to show a confirmation before going to Page 1 or Page 2, but not if Page 3 is selected. The confirmation message should be the same for Page 1 and Page 2. I'm a little confused about how to do the syntax.


Using the JavaScript from the SimpleModal Confirm Demo as an example, you could do the following:

    // 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/';
        });
    }
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜