jquery 这个变量jquery中 是什么意思思

var $v_show = $parent.find("div.v_content_list"); //寻找到“视频内容展示区域”
& 这段代码看着觉得奇怪,$() 函数 是一个 jQuery 的一个工厂,它是一个基本的创建块,但放在变量名里什么意思?有好处吗?
&
我的理解是这样的:
&&& 变量命名中是字母数字下划线 还有 $
不知道是不是这样的
表明这个是JQuery对象,区别于普通Javascript变量
已解决问题
未解决问题1、一个DOM对象和Jquery对象,即使是作为一个数组,其元素相同,但其属性是不一样的。DOM Object!=$('');&
转换的办法
Jquery=&DOM :取jQuery对象数组的第一个
var $jQueryObj=$('#id1');
var domObj=$jQueryObj[0]; //或$jQueryObj.get(0)
DOM=&jQuery 这个比较简单,直接加上$符号就可以了
var domObj=document.getElementById('#id1');
var $jQueryObj=$(dom);
2、window.onload和$(document).ready() 的区别
& 1)window.onload会在页面加载完所有元素才执行,而$(document).ready()会在Dom就绪就加载。如果直接调用一个函数,那么会最早加载。
window.onload = function () {
alert('window.onload');
//最晚,加载完全部元素,包括图片后才执行
$(function () {
alert('document.ready');
//其次,加载完DOM元素,比如表格的框架后,开始执行
function myFunction() {
alert("myFunction!");
//最早,加载完母板后就执行
myFunction();
& &2)window.onload若多次注册事件,后面的会覆盖前面的,而$(document).ready(不会覆盖,而是依次注册。
3、javascript的全局变量
全局变量在子函数中有效,如果在子函数中使用var 来改变了值,该变量的值在函数外不改变,否则,如不用var,则其变量的作用域会解析到外面。
原因在于&作用域链&这个概念。所谓作用域链,就是指函数作用范围的链条。在子函数中使用var声明变量时,链条就停止了。同样,使用function(variable){}时,作用域链也停止。&
function myFunction(){
function myFunction2(s3){
alert(s1);
//此时结果为1,s1的作用域链碰见var 即停止
alert(s2);
//此时结果为2
alert(s3);
//此时结果为2,s3的作用域链碰见将自己作为参数的函数也停止
4、在用jQuery的.each函数遍历一个jQuey对象时,有一点需要注意,在回调函数中,this是一个DOM对象,而不是jQuery对象
$('input').each(function(){
  alert(this.value);
//注意:this是一个DOM对象,而不是jQuery对象
因此,this没有val()方法,而是有value属性。
阅读(...) 评论()jQuery选择器this通过onclick传入方法以及Jquery中的this与$(this)初探,this传处变量等 - 笑剑钝 - 推酷
jQuery选择器this通过onclick传入方法以及Jquery中的this与$(this)初探,this传处变量等 - 笑剑钝
起初以为this和$(this)就是一模子刻出来。但是我在阅读时,和coding时发现,总不是一回事。
&!DOCTYPE&html&PUBLIC&
&-//W3C//DTD&XHTML&1.0&Transitional//EN&
&http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&
&html&xmlns=
&http://www.w3.org/1999/xhtml&
&meta&http-equiv=
&Content-Type&
&text/&charset=UTF-8&
&script&src=
&/ajax/libs/jquery/1.4.2/jquery.min.js&
&&/script&&&
&script&!window.jQuery&&&&document.write(
'&script&src=&js/jquery-1.4.2.min.js&&&\/script&'
&/script&&&
&script&type=
&text/javascript&
$(document).ready(
).html());&
//把DOM的this对象包装成jq对象
&/script&&&
&span&aaa&/span&&&
&span&bbb&/span&&&
&span&ccc&/span&&&
&span&ddd&/span&&&
&select&name=
&option&value=
&日志标题&/option&&&
&option&value=
&日志全文&/option&&&
&option&value=
&评论引用&/option&&&
&option&value=
&所有留言&/option&&&
&option&value=
&页面搜索&/option&&&
&/select&&&
&script&type=
&text/javascript&
&&&&alert($(
).val());&&
).html());&
//把DOM的this对象包装成jq对象
&/script&&&
/show-833-1.shtml
javascript中onclick(this) 中的this指当前什么东西?
this就是当前标签本身
onclick=xxx(this)表示一个单击事件,来进行调用xxx(this)这个JavaScript函数。而xxx(this)函数中的this表示你要进行单击对象的本身。
把this当做参数传到函数中去,实践Ok:
&!DOCTYPE&html&PUBLIC&
&-//W3C//DTD&XHTML&1.0&Transitional//EN&
&http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&
&html&xmlns=
&http://www.w3.org/1999/xhtml&
&meta&http-equiv=
&Content-Type&
&text/&charset=UTF-8&
&script&src=
&/ajax/libs/jquery/1.4.2/jquery.min.js&
&&/script&&&
&script&!window.jQuery&&&&document.write(
'&script&src=&js/jquery-1.4.2.min.js&&&\/script&'
&/script&&&
&button&id=
&test(this)&
&ccc&/button&&&&
&script&type=
&text/javascript&
&test(which){&&
//which这个参数不要写成this
&&alert($(which).attr(
&/script&&&&&
&!DOCTYPE&html&PUBLIC&
&-//W3C//DTD&XHTML&1.0&Transitional//EN&
&http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&
&html&xmlns=
&http://www.w3.org/1999/xhtml&
&meta&http-equiv=
&Content-Type&
&text/&charset=UTF-8&
&script&src=
&/ajax/libs/jquery/1.4.2/jquery.min.js&
&&/script&&&
&script&!window.jQuery&&&&document.write(
'&script&src=&js/jquery-1.4.2.min.js&&&\/script&'
&/script&&&
&select&name=
&onclick=thisTestJquery(
&option&value=
&日志标题&/option&&&
&option&value=
&日志全文&/option&&&
&option&value=
&评论引用&/option&&&
&option&value=
&所有留言&/option&&&
&option&value=
&页面搜索&/option&&&
&/select&&&
&script&type=
&text/javascript&
&thisTestJquery(th)&{&&
//th&这个参数不要写成this
&&&&alert($(th).html());&&&&
&&&&alert($(th).val());&&&&
//两种获取ID的方法
&&&&console.log(th.id);&&
&&&&console.log($(th).attr(
&/script&&&
alert($(th).html());&&&&
&option value=&1&&日志标题&/option&
&option value=&2&&日志全文&/option&
&option value=&3&&评论引用&/option&
&option value=&4&&所有留言&/option&
&option value=&5&&页面搜索&/option&
alert($(th).val());&&&&
而两种this获取Id值是这样的,实践也OK,如下:
console.log(th.id);&&
console.log($(th).attr(
$(&#exeall,#exe32,#exe64&).click(function(){&&
.id.substr(3);//这样取是Ok的:this.id&&
&&console.log($(this).id);//不能取到想要的Id&&
&&console.log(this.id);//日志打印出来Ok&&
;//这样做才能传入到get里去。&&
&&$.get(&/php/cgi/execGray.php&,para,function(data){&&
('('+data+')');&&
&&&&&&&console.log(selfObj.id);&&
通过this传入变量:
在&a 中实现Js函数的this调用:
&javascript:void(0);&
&modifyRequest(this)&
+JSON.encode(requestObj)+
&+&requestObj.f_RequestCode&+&
函数原型:
&function&modifyRequest(obj){
&&&var&requestData&=&eval('
'+$(obj).attr('
&&......&&
已发表评论数()
&&登&&&陆&&
已收藏到推刊!
请填写推刊名
描述不能大于100个字符!
权限设置: 公开
仅自己可见}

我要回帖

更多关于 jquery全局变量 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信