是否可以将这两行 jquery 合并为一行:
$(".dropdown-menu-and-or li a").click(function(){
$("#modal-button-and-or:first-child").text($(this).text());
$("#modal-button-and-or:first-child").val($(this).text());
});
最佳答案
$
或 jQuery
对象几乎由所有 jQuery 函数返回,因此当它涉及同一对象时,您可以“链接”您的调用(选择器)。
您的需求是什么?
所以,你可以这样写:
$(".dropdown-menu-and-or li a").click(function(){
$("#modal-button-and-or:first-child").text($(this).text()).val($(this).text());
});
关于javascript - 将 jquery 行合并为一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46317108/