jquery全局变量赋值和在javascript函数中使用 [英] Jquery global variable assignment and using in javascript function

查看:409
本文介绍了jquery全局变量赋值和在javascript函数中使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个全局变量listId(参考下面的代码)声明一个默认值,然后我在jq(#nav1 li a)中分配它。click(function()但是一旦其他任何javascript函数调用发生在这个函数之后,listId并不反映更改后的值,而是它只是声明中分配的默认值。我怎样才能使它反映更改后的值?

感谢

  listId ='x'; 
var jq = jQuery.noConflict(); //用于避免($#b

jq(#nav1)。click(function this.id显示在提示信息

});

函数pageSwitch(){
alert('on change id:'+ listId);
//在点击函数后调用时,这并不反映更改的值
}


解决方案

感谢guyz的帮助..实际上,这个函数是通过点击h:commandLi nk ..所以每次页面重新加载时,js的功能也是如此......我只是使用了a4j:commandLink,它工作得很好......我应该提供完整的图片..不要担心。下一次。


I have a global variable listId(refer the below code) declared with a default value and then I am assigning it inside the jq("#nav1 li a").click(function() But once any of the other javascript function call takes place after this one, the listId does not reflect the changed value, instead its just the default value assigned during declaration. How can I make it reflect the changed values?

thanks

listId = 'x';
var jq=jQuery.noConflict();// for avoiding conflict


jq("#nav1").click(function(){
  alert(this.id);
  listId = this.id; //this.id is displayed in alert message

 });

function pageSwitch(){
 alert('on change id : '+listId);
 //when called after the click function, this does not reflect changed values
 }

解决方案

Thanks guyz for the help..actually the function was invoked on click of an h:commandLink..so each time the page got reloaded and so did the js functions...I just used the a4j:commandLink and it worked fine...I should have presented the full picture..Sorry for that..will take care next time.

这篇关于jquery全局变量赋值和在javascript函数中使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆