English 中文(简体)
Jquery转换法的缩略语n
原标题:javascript to Jquery conversionn
  • 时间:2012-05-23 19:38:23
  •  标签:
  • jquery

给定 HTML 片段

<img id="progress" src="http://ajaxify.com/run/sum/progress/progress.gif" class="notWaiting"/>

传统 JavaScript 方式,

function submitWord() {
    // Show progress indicator and clear existing results
    $("progress").classname="waiting";

但以下的代码却行不通:

function submitWord() {

 // Show progress indicator and clear existing results
  $("#progress").toggleClass("notWaiting waiting");

此外,我还尝试了addClass ,甚至做了类似的事情。

$("#progress").removeClass().addClass("waiting");

只是为了确保先删除默认类,但... ain t 也帮助。

UPDATE: here is the JSfiddle version. http://jsfiddle.net/EVbh2/1/

UPDATE 2:
Now the problem above was that i dint refer to JQuery file itself . But still i am facing problems with code . I tried converting all the code into jquery but it aint working . here is a new FIDDLE.

问题回答

此工作 :

$("#progress").removeClass("notWaiting").addClass("waiting");

这也会有效, 但它会消灭你所有其他的班级, 而唯一的班级将是“等待”:

$("#progress").attr("class","waiting");

这也会有效,而且很可能是最简单的:

$("#progress").toggleClass("notWaiting waiting");

<强> UPDATE

在看着你的小提琴后,你的问题实际上是 你忘了在选择“字”时放 #。我还修改了你的键盘功能, 以使用 jquery 等量的 。

此工作 :

http://jsfiddle.net/wuXL2/3/

您的 jsFiddle demo 是 not 正确的 jQuery 代码。 在 jQuery 中, $ 返回jQuery 对象, 而不是 DOM 元素。 因此, 您无法以同样的方式设置属性 。 因此您无法这样做 :

$("word").onkeyup = function(){
};

您需要调用 keyup 方法 :

$( #word ).keyup(function(){  // Note the  # 
});

此外:

$("results").innerHTML = "";

应:

$("#results").html("");  // Note the  # 

关于改变班级:

$("#progress").toggleClass("notWaiting waiting");

这是对的, 在 jQuery 中百分百有效 。 如果它不起作用, 那么其他的也是错误的( 比如错误的 jQuery 代码, 以及您的 jsFiddle 选择了 MooTools ) 。

固定模版:http://jsfiddle.net/EVbh2/3/" rel=“no follow”>http://jsfiddle.net/EVbh2/3/

问题在于染色体。在IE中,它非常有效。





相关问题
getGridParam is not a function

The HTML: <a href="javascript:void(0)" id="m1">Get Selected id s</a> The Function: jQuery("#m1").click( function() { var s; s = jQuery("#list4").getGridParam( selarrrow )...

selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

jQuery cycle page with links

I am using the cycle plugin with pager functionality like this : $j( #homebox ) .cycle({ fx: fade , speed: fast , timeout: 9000, pager: #home-thumbs , ...

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

jConfirm with this existing code

I need help to use jConfirm with this existing code (php & Jquery & jAlert). function logout() { if (confirm("Do you really want to logout?")) window.location.href = "logout.php"; } ...

Wrap text after particular symbol with jQuery

What I m trying to do, is wrap text into div inside ll tag. It wouldn t be a problem, but I need to wrap text that appears particularly after "-" (minus) including "minus" itself. This is my html: &...