简体   繁体   English

jQuery将基于id的元素更改为其他类

[英]jquery change an element based on id to a different class

I am trying to grey out the Finish button in jquery steps (like the Previous button in the image below, for steps 1 and steps 2 in my wizard. The third and final step will enable the Finish button. 我正在尝试将jquery步骤中的“完成”按钮显示为灰色(例如下图中的“上一步”按钮,对于向导中的步骤1和步骤2。第三步,也是最后一步,将启用“完成”按钮。

在此处输入图片说明

I thought the best approach is to set 我认为最好的方法是

enableFinishButton: true 

so it is available for manipulation. 因此可以进行操作。

I inspected the grayed out 'Previous' button in chrome editor and I saw this: 我在Chrome编辑器中检查了显示为灰色的“上一步”按钮,然后看到了:

在此处输入图片说明

It seems to me that I want the id="finish_button" to appear in the 在我看来,我希望id =“ finish_button”出现在

<li class = "disabled" aria-disabled="true"> 

along with the Previous button in Step 1, and remain there in Step 2, then move to 以及步骤1中的“上一步”按钮,并保留在步骤2中,然后移至

  <li class = "aria-hidden ="false"" aria-disabled="false">

in Step 3. It would also be nice to move the Next button to 在步骤3中。将“下一步”按钮移至

  <li class = "disabled" aria-disabled="true"> 

in that third and final step. 在第三步也是最后一步。

I have no idea how to move an element by id around these different classes based on user clicks. 我不知道如何根据用户点击在这些不同的类之间通过id移动元素。

Thanks for any help anyone can provide. 感谢您提供任何帮助。

Tom 汤姆

I have some examples of what I think you are looking for: 我有一些我认为您正在寻找的示例:

// move an element to another element

$("#finish_button").appendTo("li.disabled");

// or leave element where it is and change attributes and classes

$("li[aria-hidden='false']").attr("aria-disabled","true");
$("li[aria-hidden='false']").addClass("disabled");

// set up onclick events for the buttons to make these types of changes

$("#next_button").click(function() { 
  // code to run when next is clicked
  // like enable finish button, disable next button.
  $("li.disabled").removeClass("disabled");
});

These may not be the exact selectors you will need to use, depending on if there could be other li elements on the page with similar attributes. 这些可能不是您将需要使用的确切选择器,具体取决于页面上是否可能存在其他具有相似属性的li元素。

The onclick and href can work together as long as the click function does not return false, or run preventDefault() on the click event. 只要click函数不返回false,或者可以对click事件运行preventDefault(),onclick和href可以一起工作。

I hope it helps. 希望对您有所帮助。

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

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