我有一个纯JS函数,其中我试图将多数转换为jquery。如何将整个功能设置为正确的jquery syntax
?
function openResources(e, resourceName) {
var i, tabcontent, tabs;
tabcontent = $(".resources__all-tabs-container");
for (i = 0; i < tabcontent.length; i++) {;
tabcontent[i].style.display = "none";
}
tabs = $(".resources__tabs");
for (i = 0; i < tabcontent.length; i++) {
tabs[i].className = tabs[i].className.replace("
resources__all-tabs", "");
}
document.getElementById(resourceName).style.display= "block";
//$(`"`+ resourceName + `"`)[0].style.display ="block";
e.currentTarget.className += " resources__all-tabs";
}
答案 0 :(得分:1)
此:
tabcontent = $(".resources__all-tabs-container");
for (i = 0; i < tabcontent.length; i++) {;
tabcontent[i].style.display = "none";
}
将是:
$(".resources__all-tabs-container").hide();
见这里:http://api.jquery.com/hide/
此:
tabs = $(".resources__tabs");
for (i = 0; i < tabcontent.length; i++) {
tabs[i].className = tabs[i].className.replace("resources__all-tabs", "");
}
应替换为:
$(".resources__tabs").removeClass("resources__all-tabs")
见这里:https://api.jquery.com/removeclass/
此:
document.getElementById(resourceName).style.display= "block";
必须替换为:
$("#" + resourceName).show();
见这里:http://api.jquery.com/show/
此:
e.currentTarget.className += " resources__all-tabs";
应该是:
$(e.currentTarget).addClass("resources__all-tabs");
答案 1 :(得分:0)
不要忘记你可以在jQuery中链接函数。
function openResources(e, resourceName) {
$(".resources__all-tabs-container").hide();
$(".resources__tabs").removeClass('resources__all-tabs');
$('#' + resourceName).show();
$(e.currentTarget).addClass('resources__all-tabs');
}
答案 2 :(得分:0)
function openResources(e, resourceName) {
$(".resources__all-tabs-container").hide();
$(".resources__tabs").removeClass("resources__all-tabs");
$("#" + resourceName).show();
$(e.currentTarget).addClass("resources__all-tabs");
}
应该是等效代码。
答案 3 :(得分:0)
function openResources(e, resourceName) {
var tabcontent = $(".resources__all-tabs-container"),
tabs = $(".resources__tabs");
// hide all tabs and show the one that matches `resourceName`
tabcontent.hide().filter('#' + resourceName).show();
// set current tab as selected
$(e.target).addClass('resources__all-tabs')
}
答案 4 :(得分:-1)
这样的事情:
public class ARInvoiceEntry_Extension:PXGraphExtension<ARInvoiceEntry>
{
protected void ARInvoice_RowPersisting(PXCache cache, PXRowPersistingEventArgs e, PXRowPersisting InvokeBaseHandler)
{
var row = (ARInvoice)e.Row;
if (row != null)
{
//BB-<timestamp> as inv# for testing only
if (string.IsNullOrEmpty(row.RefNbr))
row.RefNbr = "BB-" + DateTime.Now.ToString("hhmmsstt");
}
if(InvokeBaseHandler != null)
InvokeBaseHandler(cache, e);
}
}