0

クリックした要素の href を取得して関数に渡すのに問題があります。何か案は?

$('#smoke_confirm').click(function(e){
            var href = $(this).attr("href");
            tstconfirm(href);
            e.preventDefault();
        });

        function tstconfirm(href){
            smoke.confirm('Are you sure you want to delete?',function(e){
                if (e){
                    window.location = $(href);
                }
            }, {cancel:"cancel", ok:"confirm"});
        }
4

2 に答える 2

2

ここの href はテキストであるため$(href)、href 値を持つ要素を選択しようとするため正しくありません。するだけですwindow.location = href。また、href を取得したいだけの場合は、DOM 要素のプロパティである jquery インスタンスを作成する必要thisはありません。this.href

$('#smoke_confirm').click(function(e){
            var href = this.href;
            tstconfirm(href);
            e.preventDefault();
        });

        function tstconfirm(href){
            smoke.confirm('Are you sure you want to delete?',function(e){
                if (e){
                    window.location = href;
                }
            }, {cancel:"cancel", ok:"confirm"});
        }
于 2013-06-17T21:16:47.277 に答える
1

href文字列です

 window.location = $(href); // This will try to convert it to a jQuery object

察するに

 window.location = href;
于 2013-06-17T21:16:27.673 に答える