如何设置页面加载时默认单击的列表项



当页面加载时,我有一个动态创建的列表视图,我想设置默认情况下单击的第一个列表项,我如何使用jQuery/javascript做到这一点?

这样做:

$(function () {
  // Give the below one, or use the perfect selector for your first <li>
  $("li").first().trigger("click");
});

或者如果你使用<select>标记,你需要以不同的方式处理它:

$(function () {
  // Give the below one, or use the perfect selector for your first <select>
  $("select option").first().prop("selected", true);
});

最新更新