所以在我的代码中< /a> 我用过
function $(id) { return document.getElementById(id); }
我想转移到 jQuery。怎么翻译这样的东西呢?
So in my code I used
I want to move to jQuery. How to translate such thing to it?
不要使用此函数,function $(id)。使用 jQuery 函数 $('#id')。这个函数将返回一个带有一堆 jQuery 方法的对象。
function $(id)
$('#id')
方法有remove()、hide()、toggle()等,实现如$('# id').hide()、$('#id').show() 等。
remove()
hide()
toggle()
$('# id').hide()
$('#id').show()
jQuery 方法有很多很多,可以通过多种方式简化它。
Don't use this function, function $(id). Use the jQuery function $('#id'). This function will return an object with bunch of jQuery methods.
Methods include remove(), hide(), toggle(), etc., and the implementation is like $('#id').hide(), $('#id').show(), etc.
$('#id').hide()
There are so many, many jQuery methods, that simplifies it in so many ways.
如果我的问题正确,您将需要在页面中包含 jQuery,并将以下行:
return document.getElementById(id);
替换为以下行:
return $("# “+id);
If I got your question right, you will need to include jQuery inside your page, and replace the following line:
with this one:
return $("#"+id);
使用 Jquery 选择器,您可以非常轻松地完成同样的事情。
$("#" + id)
有关更多详细信息:
http://api.jquery.com/id-选择器/
Using Jquery selectors you can do the same thing very easily.
For more details:
http://api.jquery.com/id-selector/
只需使用
$("#"+id)
That 就会返回具有正确 ID 的元素。
Just use
That will return the element with the right ID.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
暂无简介
文章 0 评论 0
接受
发布评论
评论(4)
不要使用此函数,
function $(id)
。使用 jQuery 函数$('#id')
。这个函数将返回一个带有一堆 jQuery 方法的对象。方法有
remove()
、hide()
、toggle()
等,实现如$('# id').hide()
、$('#id').show()
等。jQuery 方法有很多很多,可以通过多种方式简化它。
Don't use this function,
function $(id)
. Use the jQuery function$('#id')
. This function will return an object with bunch of jQuery methods.Methods include
remove()
,hide()
,toggle()
, etc., and the implementation is like$('#id').hide()
,$('#id').show()
, etc.There are so many, many jQuery methods, that simplifies it in so many ways.
如果我的问题正确,您将需要在页面中包含 jQuery,并将以下行:
return document.getElementById(id);
替换为以下行:
return $("# “+id);
If I got your question right, you will need to include jQuery inside your page, and replace the following line:
return document.getElementById(id);
with this one:
return $("#"+id);
使用 Jquery 选择器,您可以非常轻松地完成同样的事情。
$("#" + id)
有关更多详细信息:
http://api.jquery.com/id-选择器/
Using Jquery selectors you can do the same thing very easily.
$("#" + id)
For more details:
http://api.jquery.com/id-selector/
只需使用
That 就会返回具有正确 ID 的元素。
Just use
That will return the element with the right ID.