如何在JS中通过引用传递变量?我有3个变量,我想要执行几个操作,所以我想将它们放在for循环中并对每个变量执行操作.
伪代码:
myArray = new Array(var1, var2, var3);
for (var x = 0; x < myArray.length; x++){
//do stuff to the array
makePretty(myArray[x]);
}
//now do stuff to the updated vars
Run Code Online (Sandbox Code Playgroud)
做这个的最好方式是什么?
我有一个基于ajax的应用程序,其中我只有一个登录页面和主页面.
我的大部分链接都是"ajaxed"我和我这样做:
//get the href of the link that has been clicked, ajaxify ANY links
$(document).on('click', '.tree a', function () {
var link = $(this).attr('href'); //get the href off the list
$.ajax({ //ajax request to post the partial View
url: link,
type: 'POST',
cache: false,
success: function (result) {
$('#target').html(result);
$.validator.unobtrusive.parse($("form#ValidateForm"));
}
});
return false; //intercept the link
});
Run Code Online (Sandbox Code Playgroud)
我想在我的应用程序上实现"pushState",我到目前为止所做的第一步是添加以下代码:
$(document).on('click', 'a', function () {
history.pushState({}, '', $(this).attr("href"));
});
Run Code Online (Sandbox Code Playgroud)
现在,每当我点击任何链接并成功加载ajax内容时,它都会更新我的地址栏.我是这个API的新手,所以我不知道我错过了什么,但到目前为止我的问题是:
当我按下"后退"按钮时,没有任何反应.我读到了关于"popstate"并浏览了SO以寻找解决方案,但我似乎无法让它们发挥作用.
当我点击历史记录中的链接时,我从主html获得了没有布局的子html的"原始"视图.如果我希望它显示为从我的主应用程序中点击它,我需要做什么?
我的大多数孩子观点都是表格或列表.
为什么以下不起作用?显然该功能尚未添加!
function activatetypeinput(event, devtype){
//The function is called but it doesn't set the attribute
var dev_input = document.getElementById("device_input");
dev_input.setAttribute("onclick","add_device_input(event, this);");
}
Run Code Online (Sandbox Code Playgroud)
在我的 HTML 中,我有这样的内容(除其他外):
<select class="text-input" id="device_input">
<option>--</option>
</select>
Run Code Online (Sandbox Code Playgroud) 什么工具、方法最适合分别获取每个WP 函数的执行时间。理想情况下,我希望看到一个列表,如下图所示:
这是“调试栏”插件的 UI,带有“慢动作”插件,这是一个好的开始,但现在对我来说还不够,因为它只显示钩子本身的总运行时间,而不显示各个函数(回调)一一附加到它们上。
见下图:
因此,我也很高兴看到每个功能的单独时间。
到目前为止,这个插件让我最接近这个,它肯定是一个有价值的产品,但是有可能对其进行改进吗?--> 我们是否知道任何现成的解决方案(自定义代码或产品)?
(作为参考,这里是我在研究这个主题期间发现的一个较旧的相关问题。在这里我计划检查 Xdebug,但首先我想找到 Wordpress 特定的工具。)
感谢您的任何帮助/提示!
最好的,
维克托