首页 \ 问答 \ 单行Bash无限while循环语法(Syntax for a single-line Bash infinite while loop)

单行Bash无限while循环语法(Syntax for a single-line Bash infinite while loop)

我遇到了分号和/或大括号的正确组合。 我想这样做,但作为一个单行从命令行:

while [ 1 ]
do
    foo
    sleep 2
done

I am having trouble coming up with the right combination of semicolons and/or braces. I'd like to do this, but as a one-liner from the command line:

while [ 1 ]
do
    foo
    sleep 2
done

原文:https://stackoverflow.com/questions/1289026
更新时间:2022-04-15 15:04

最满意答案

您必须在元素存在后绑定事件。 使用ready事件在加载所有页面时运行代码:

$(document).ready(function(){
  $('body').on('click', 'a.wishlist_item', function(e){
    alert('asas');
    e.preventDefault();
  });
});

You have to bind the event after the element exists. Use the ready event to run the code when all the page is loaded:

$(document).ready(function(){
  $('body').on('click', 'a.wishlist_item', function(e){
    alert('asas');
    e.preventDefault();
  });
});

相关问答

更多
  • 关于短版本: $('.enableSelects').click(function(){ $('select').prop('disabled', !$('select').prop('disabled')); });​ 从...开始: $('select').prop('disabled', !$('select').prop('disabled')); // | ||__________________________| // ...
  • 您必须在元素存在后绑定事件。 使用ready事件在加载所有页面时运行代码: $(document).ready(function(){ $('body').on('click', 'a.wishlist_item', function(e){ alert('asas'); e.preventDefault(); }); }); You have to bind the event after the element exists. Use the ready event to ru ...
  • 内部仍然,而不是typical href="#"或href="javascript:void"或href="whatever" ,我认为这更有意义: var el = document.getElementById('foo'); el.onclick = showFoo; function showFoo() { alert('I am foo!'); return false; }
  • 尝试使用setTimeout() var tOut; $('.menu').on('mousedown', function () { console.log("this is less than one second"); tOut = setTimeout(function () { alert("Holded more than one second"); }, 1000); }); $('.menu').on('mouseup', function () { ...
  • 附加事件时,链接不在DOM内部。 对于动态生成的元素,您应该使用它 。 你能试一下吗 : $(document).on('click','.js-not-found', function (e) { e.preventDefault(); // some stuff }); 为了获得更好的性能,建议在生成元素的DOM中使用直接祖先: $(".container").on('click','.js-not-found', function (e) { e.preventDefault ...
  • 你走了:这很好用 http://jsfiddle.net/6g4j2/ $(document).ready(function(){ $("#mainNav ul a, .logo a, .shortcat a, .notBtn a").click(function(event){ var full_url = this.href; var parts = full_url.split("#"); var trgt = parts[1]; ...
  • 感谢Anon SO用户: http : //jsfiddle.net/fdr6y6y7/1/ $('#thumb_scroll a').click(function(event) { $('#largeimg img').attr("src", $(this).attr("href")); $('#largeimg a').attr("href", $(this).attr("href")); return false; });