简体   繁体   English

使用jQuery作为选择器,使用JavaScript,是否可能?

[英]Using jQuery as a selector, working with JavaScript, is it possible?

var helper, kitti, amount;
if (i == 0) { 
    helper = "#k" + ids+ " .contain";
}
else {
    helper = "#k" + ids + " .d" + i;
}    
kitti = "$(" + helper + ").get(0)";
amount = (MouseX-kitti.width / 2) * layer[i - 1] * 2;
kitti.style.transform = "rotateY(" + amount * 50 + "deg)";
kitti.style.left = amount + "px";

This part of my code doesn't seem to work but. 我的代码的这部分似乎不起作用。 I bet I did something wrong selecting it? 我打赌我做错了选择它? I've read a couple of articles and I came to this conclusion. 我读了几篇文章,然后得出了这个结论。 But it does not work, can you explain me why? 但它不起作用,你能解释一下为什么吗? How can I select classes with jQuery and after that continue with plain Javascript? 如何使用jQuery选择类,然后继续使用纯Javascript?

You've made some simple syntax errors here. 你在这里做了一些简单的语法错误。 I personally don't care for the style in which you're written your code, but I will do my best to suggest what the fix might be. 我个人并不关心您编写代码的样式,但我会尽力建议修复可能的内容。

In the second line, you write kitti = "$(" + helper + ").get(0)" . 在第二行,你写kitti = "$(" + helper + ").get(0)" The problem here is that $ is a function defined in the jQuery library and you are treating it as a string. 这里的问题是$是jQuery库中定义的函数,你将它视为一个字符串。

The result here will be to assign a string value to the variable kitti . 这里的结果是为变量kitti分配一个字符串值。 You also appear to be using an undefined variable ids in line 1. The correct syntax would be something like this: 您似乎也在第1行中使用了未定义的变量ids 。正确的语法将是这样的:

var kitti = $(helper).get(0);

I don't want to be overbearing, but from the syntax of the code in your question, you might benefit from reading a book on good JavaScript such as "JavaScript: The Good Parts", by Douglas Crockford. 我不想咄咄逼人,但是根据你问题中代码的语法,你可能会从阅读好书的书中受益,例如道格拉斯克罗克福德的“JavaScript:The Good Parts”。 There is also lots of good information available for free on his web site. 他的网站上还有许多免费的免费信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM