将参数传递给jQuery'Load' [英] Passing Parameters to a jQuery 'Load'
本文介绍了将参数传递给jQuery'Load'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的页面上有一些脚本,
I have some script on my page which is:
$('#divMenuHolder').load('../menu.html');
但是,我还需要能够传递一些在menu.html页面上执行的参数.
However I also need to be able to pass some parameters which are acted on the menu.html page.
我尝试了以下操作:
$('#divMenuHolder').load('../menu.html?opt1=test&opt2=test2');
但是,当我使用以下函数获取参数时:
However when I come to get the parameters using the following function:
function getUrlVars()
{
var vars = [], hash;
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
for(var i = 0; i < hashes.length; i++)
{
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
return vars;
}
它什么也不返回,因为它试图获取页面本身的参数,而不是我要加载到DIV中的页面.
It returns nothing because it's trying to get the parameters of the page itself, and not the page I'm loading into DIV.
反正可以帮助我找到我想要的东西吗?
Can anyway assist in guiding me to what I want please?
推荐答案
这对我有用
$('#semester').load("restricted/getSemester.php?courseid=" + $("#course").val());
其中#course
是输入字段的ID.
where #course
is id of input field.
或
$('#subject').load("restricted/getSubject.php?courseid=0&semester=0");
我希望这对您有帮助:)
I hope this helps u :)
这篇关于将参数传递给jQuery'Load'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文