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/
,如需转载,请注明出处,否则将追究法律责任。