ITPub博客

首页 > Linux操作系统 > Linux操作系统 > Javascript note

Javascript note

原创 Linux操作系统 作者:mbs06061 时间:2012-09-20 14:32:49 0 删除 编辑

These days, I am involved to tune SBS-UI-Framework and fix its bugs. There are much knowledge about

Web UI I want to record and share with developers.As belows:

  1.Logic Operator(It's a little different from tradition operator)

    &&  return that which operand can be converted to false;

           return true if both are true,otherwise, return false;

     ||    return that which operand can be converted to true;

           return true if both are true,otherwise, return false;

  2.How to let browser open a new page in a new tab?

     decided by the browser setting and your code. But at least we can set the target to control the behavior.

  • window.open(url, '_blank');
  • window.focus();
  • $('#NewTab').click(function()
  • { $(this).target = "_blank";
  • window.open($(this).prop('href'));
  • return false; });

 3.How to replace a range in CodeMirror?  

  • var from = codemirror.getCursor(true);
  • var to = codemirror.getCursor(false);
  • getRange(from,to);
  • var start = from.line;
  • var end = to .line;
  • replaceRange("",{ln:start,ch:0},{ln:end+1,ch:0});

 4.event.preventDefault();event.stopPropagation();return false

     preventDefault(): prevent the default action binding to the event from occuring if it event.cancelable is true;
     stopPropagation():prevent event propagation between different document elements.
     return false: same as preventDefault()  in non-JQuery;but in JQuery it can prevent default action and bubbling up.
     example:
  •     $(document).keydown(function(evt) {
  •         var currKey=0,e=evt||event;
  •         currKey=e.keyCode||e.which||e.charCode;
  •         if (!( String.fromCharCode(currKey).toLowerCase() == 'r' && event.ctrlKey) && !(currKey== 19)) return true;
  •         saveFile();
  •         return false;//e.preventDefault();
  •      });


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/23674512/viewspace-744450/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: 没有了~
下一篇: 没有了~
请登录后发表评论 登录
全部评论

注册时间:2011-12-30

  • 博文量
    1
  • 访问量
    324