嗨,我想在单击复选框时重写url参数值, 类似于亚马逊搜索。过滤 我尝试使用此代码
namespace TacticalAILib
{
public class CalculateFrontages
{
static int[] U;
private static TacLineStruct CalculateLines(List<MATEUnit> Army, double MetersPerPixel, int MSTGapValue)
{
int TempFrom, TempTo;
float TempWeight;
int NumEdges = 0;
double Threshold = MetersPerPixel * MSTGapValue;
U = new int[Army.Count];
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script language="javascript1.2">
$(document).ready(function () {
$('input[type=checkbox]').click(function (e) {
var seasoning = '', tempArray = [];
$('input[name="vegetables[]"]:checked').each(function(){
tempArray.push($(this).val());
})
if(tempArray.length !== 0){
seasoning+='vegetables='+tempArray.toString();
tempArray = [];
}
$('input[name="seasoning[]"]:checked').each(function(){
tempArray.push($(this).val());
})
if(tempArray.length !== 0){
seasoning+='&seasoning='+tempArray.toString();
}
//window.location ='http://localhost/sss.php?'+seasoning;
console.log('http://localhost/sss.php?'+seasoning);
});
});
</script>
但它仅在控制台中运行 我无法修复它以url运行 我想要将参数附加到网址
答案 0 :(得分:0)
使用document.location.search += seasoning
使页面刷新。
window.history.replaceState(null, null, 'http://localhost/sss.php?'+seasoning);
或
window.history.replaceState(null, null, 'http://localhost/sss.php?'+seasoning);
$(document).ready(function () {
$('input[type=checkbox]').click(function (e) {
var seasoning = '', tempArray = [];
$('input[name="vegetables[]"]:checked').each(function(){
tempArray.push($(this).val());
})
console.log(tempArray);
if(tempArray.length !== 0){
seasoning+='vegetables='+tempArray.toString();
tempArray = [];
}
$('input[name="seasoning[]"]:checked').each(function(){
tempArray.push($(this).val());
});
if(tempArray.length !== 0){
seasoning+='&seasoning='+tempArray.toString();
}
console.log('http://localhost/sss.php?'+seasoning);
});
});
<div>
<p>Select vegetables</p>
<label><input type="checkbox" name="vegetables[]" value="potato"> Potato</label><br>
<label><input type="checkbox" name="vegetables[]" value="onion"> Onion</label><br>
<label><input type="checkbox" name="vegetables[]" value="tomato"> Tomato</label><br>
</div>
<div>
<p>Select seasoning</p>
<label><input type="checkbox" name="seasoning[]" value="salt"> Salt</label><br>
<label><input type="checkbox" name="seasoning[]" value="pepper"> Pepper</label><br>
<label><input type="checkbox" name="seasoning[]" value="chilli"> Chilli Flakes</label><br>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.3/jquery.min.js"></script>