如果使用jQuery启用javascript,我将所有页面元素从单独的加载转换为Ajax页面。我做了大部分事情,但我需要检查的一件事是onclick/onchange事件。jQuery找到location.href并用函数替换
我有这样的:
$("select").each(function(){
if ($(this).attr('onchange')) {
//CHECK FOR LOCATION.HREF
}
return false;
});
和需要改变的东西,如:
location.href='/calendar-of-events/'+escape(this.options[this.selectedIndex].value)+'/5/2011/
到:
pageload('/calendar-of-events/'+escape(this.options[this.selectedIndex].value)+'/5/2011/')
我会怎么做呢?
谢谢。
编辑:
我想:
$("select").each(function(){
if ($(this).attr('onchange')) {
var ocval = $(this).attr('onchange');
ocval = ocval.replace('location.href=','pageload(');
ocval = ocval+')';
$(this).attr('onchange',ocval);
}
return false;
});
,但不起作用。 onchange值是一个函数。
function onchange(event) {
location.href = "/calendar-of-events/" + escape(this.options[this.selectedIndex].value) + "/5/2011/";
}
我该如何改变这种情况?
你回答了你自己的问题,好样的! – 2011-05-12 22:21:01
最新的问题是什么? – Neal 2011-05-12 22:21:32
我正在寻找代码来替换location.href,并围绕url包装pageload函数。问题是我需要确保onchange中没有其他功能。在这种情况下,我可以在字符串的末尾替换location.href = pageload(然后添加一个),但是如果还有其他东西,我需要找到location.href的结尾。 – fanfavorite 2011-05-13 12:59:50