2016-04-08 2 views
0

に行くために:基本的に私がチェックボックスの値をJSがチェックボックスの値がURLに追加取得し、クリック時に、私はこのようになりますスクリプトいるURL

var baseUrl = 'http://ab3.0e7.myftpupload.com/idmatch_process.php?idmatch_process.php?quizid=". urlencode($quiz_id) ."&escalation=". urlencode($escalation) ."&correctrule=". urlencode($correctrule) ."&page=" . $next_page ."&ans='; 

$(document).ready(function() { 

// listen to change event (customize selector to your needs) 
$('input[type=checkbox]').change(function (e) { 

    e.preventDefault(); 

    if ($(this).is(':checked')) { 

     // read in value 
     var queryString = $(this).val(); 

     // loop through siblings (customize selector to your needs) 
     var s = $(this).siblings(); 
     $.each(s, function() { 

      // see if checked 
      if ($(this).is(':checked')) { 

       // append value 
       queryString += ' OR ' + $(this).val(); 
      } 
     }); 

     // jump to url 
     window.location = baseUrl + queryString; 
    } 
}); 

}); 

を取得していますし、その後にそれを追加とbaseUrlのです。それから私は自動的にウィンドウの場所を変更しています。私がしたいのは、チェックボックスのクリックではなく、ボタンのクリックで追加するウィンドウの位置の変更を持たせることです。誰でも簡単な方法でこれを行うことができますか?

答えて

1

ulrをグローバル変数に格納します。

urlが空でない場合にのみボタンを表示し、クリック時にリダイレクトします。

var baseUrl = 'http://ab3.0e7.myftpupload.com/idmatch_process.php?idmatch_process.php?quizid=". urlencode($quiz_id) ."&escalation=". urlencode($escalation) ."&correctrule=". urlencode($correctrule) ."&page=" . $next_page ."&ans='; 

var newurl=""; 

$(document).ready(function() { 

// listen to change event (customize selector to your needs) 
$('input[type=checkbox]').change(function (e) { 

    e.preventDefault(); 

    if ($(this).is(':checked')) { 

     // read in value 
     var queryString = $(this).val(); 

     // loop through siblings (customize selector to your needs) 
     var s = $(this).siblings(); 
     $.each(s, function() { 

      // see if checked 
      if ($(this).is(':checked')) { 

       // append value 
       queryString += ' OR ' + $(this).val(); 
      } 
     }); 

     // jump to url 
     newurl = baseUrl + queryString; //setting new url 
     $("#yourbutton").show(); 
    } 
}); 

    $("#yourbutton").click(function(){ 
    if(newurl!="") 
     window.location.href=newurl; 
} 

}); 
0

ボタンを作成して、ドキュメント上で現在行っている作業をonclickで実行できます。

1

queryStringの宣言を外側のスコープに移動すると、後でクリックすると使用できます。

$(document).ready(function() { 
    var queryString = ''; 

    // listen to change event (customize selector to your needs) 
    $('input[type=checkbox]').change(function (e) { 

    e.preventDefault(); 

    if ($(this).is(':checked')) { 
     // read in value 
     queryString = $(this).val(); 

     // loop through siblings (customize selector to your needs) 
     var s = $(this).siblings(); 
     $.each(s, function() { 
     // see if checked 
     if ($(this).is(':checked')) { 
      // append value 
      queryString += ' OR ' + $(this).val(); 
     } 
     }); 
    } 
    }); 

    $('button.submit').on('click', function() { 
    // jump to url 
    window.location = baseUrl + queryString; 
    }); 
}); 
関連する問題