无法使用包含 url 变量的 javascript 函数刷新到页面底部
Cant refresh to bottom of page with javascript function containing url variables
我的php页面底部有一些级联下拉菜单。每次用户从下拉列表中选择一个选项时,都会调用以下函数以将该选项的值添加到我的 url 变量中。目前,页面每次都会刷新到顶部,这是一个巨大的问题。通常我会使用 onCLick="window.location='page.htm#bottom';" 之类的东西刷新到页面底部,但当我添加 #bottom 时,下面的函数停止工作。有人可以帮我调整此功能或给我其他想法,这些想法将在功能完成后刷新到页面底部。
function reload5(form){
if(document.getElementById('fda1').checked) {
var fda = '1';
}else if(document.getElementById('fda0').checked) {
var fda = '0';
}
var val=form.category.options[form.category.options.selectedIndex].value;
var val2=form.subcat.options[form.subcat.options.selectedIndex].value;
var val3=form.subcat1.options[form.subcat1.options.selectedIndex].value;
var val4=form.subcat2.options[form.subcat2.options.selectedIndex].value;
var comp1=form.mname.options[form.mname.options.selectedIndex].text;
var itemnum=document.getElementById('item').value;
var desc=document.getElementById('desc').value;
var quan=document.getElementById('quan').value;
var list=document.getElementById('list').value;
var uom=form.uom.options[form.uom.options.selectedIndex].text;
self.location='add_products.php#bottom?fda=' + fda + '&desc=' + desc + '&quan=' + quan + '&list=' + list + '&uom=' + uom + '&item=' + itemnum + '&cat=' + val + '&cat2=' + val2 + '&cat3=' + val3 + '&cat4=' + val4 + '&comp=' + comp1 ;
}
所以这行不通:self.location='add_products.php#bottom?fda=' + fda
但这确实是:self.location='add_products.php?fda=' + fda
知道把 #bottom 放在哪里吗?
问题是哈希必须在末尾的查询字符串之后。 请参阅此文章。 试试这个...(我也清理了代码)
function reload5(form){
var val=form.category.options[form.category.options.selectedIndex].value,
val2=form.subcat.options[form.subcat.options.selectedIndex].value,
val3=form.subcat1.options[form.subcat1.options.selectedIndex].value,
val4=form.subcat2.options[form.subcat2.options.selectedIndex].value,
comp1=form.mname.options[form.mname.options.selectedIndex].text,
itemnum=document.getElementById('item').value,
desc=document.getElementById('desc').value,
quan=document.getElementById('quan').value,
list=document.getElementById('list').value,
uom=form.uom.options[form.uom.options.selectedIndex].text,
fda;
if(document.getElementById('fda1').checked) {
fda = 1;
} else if(document.getElementById('fda0').checked) {
fda = 0;
} else {
fda = -1;
}
window.self.location.href = 'add_products.php?fda=' + fda + '&desc=' + desc + '&quan=' + quan + '&list=' + list + '&uom=' + uom + '&item=' + itemnum + '&cat=' + val + '&cat2=' + val2 + '&cat3=' + val3 + '&cat4=' + val4 + '&comp=' + comp1 + "#bottom";
}
我不明白的是,为什么你不使用Ajax做一些根本不会导致页面刷新的事情。
相关文章:
- 停止对document.ready函数的重定向/刷新
- 刷新按钮以调用javascript函数
- j查询如何在加载了 load() 函数的页面上进行 POST/AJAX,而无需刷新页面
- 如何等到iframe刷新完成后再执行函数
- 如何使用AJAX函数在不刷新页面的情况下发送表单,我缺少什么?我必须为此使用休息框架吗?
- Javascript 函数在页面刷新时不可用
- onchange 函数需要时间来刷新页面
- 如何将数据从表单传递到 php 函数到 javascript 以在画布上绘制而不刷新页面
- 需要 Ajax 函数 - 在不刷新页面的情况下更新数据库
- 使用 Javascript 在页面刷新时调用函数
- 刷新函数未正确调用 d3
- AJAX/JQuery:提交表单和调用函数而不刷新页面
- 如何在不刷新页面的情况下多次执行构造函数
- jQuery - 刷新每个()函数
- Jquery 移动函数不起作用 == 页面刷新
- 具有剑道网格刷新的回调函数
- 页面刷新函数的回调函数
- 刷新函数内的javascript if语句
- 如何处理IE中多次刷新函数的框背景颜色
- 更新刷新函数中的挖空可观察字符串