caret

What does the caret operator (^) in Python do?

北城余情 提交于 2019-11-26 09:23:57
问题 I ran across the caret operator in python today and trying it out, I got the following output: >>> 8^3 11 >>> 8^4 12 >>> 8^1 9 >>> 8^0 8 >>> 7^1 6 >>> 7^2 5 >>> 7^7 0 >>> 7^8 15 >>> 9^1 8 >>> 16^1 17 >>> 15^1 14 >>> It seems to be based on 8, so I\'m guessing some sort of byte operation? I can\'t seem to find much about this searching sites other than it behaves oddly for floats, does anybody have a link to what this operator does or can you explain it here? 回答1: It's a bitwise XOR (exclusive

Carets in Regular Expressions

只愿长相守 提交于 2019-11-26 08:29:27
Specifically when does ^ mean "match start" and when does it mean "not the following" in regular expressions? From the Wikipedia article and other references, I've concluded it means the former at the start and the latter when used with brackets, but how does the program handle the case where the caret is at the start and at a bracket? What does, say, ^[b-d]t$ match? ^ only means "not the following" when inside and at the start of [] , so [^...] . When it's inside [] but not at the start, it means the actual ^ character. When it's escaped ( \^ ), it also means the actual ^ character. In all

Get caret position in HTML input?

十年热恋 提交于 2019-11-26 04:25:16
问题 How do I get the index of the text caret in an input? 回答1: -> selectionStart <!doctype html> <html> <head> <meta charset = "utf-8"> <script type = "text/javascript"> window.addEventListener ("load", function () { var input = document.getElementsByTagName ("input"); input[0].addEventListener ("keydown", function () { alert ("Caret position: " + this.selectionStart); // You can also set the caret: this.selectionStart = 2; }); }); </script> <title>Test</title> </head> <body> <input type = "text"

Styling text input caret

隐身守侯 提交于 2019-11-26 01:38:06
问题 I want to style the caret of a focused <input type=\'text\'/> . Specifically, the color and thickness. 回答1: If you are using a webkit browser you can change the color of the caret by following the next CSS snippet. I'm not sure if It's possible to change the format with CSS. input, textarea { font-size: 24px; padding: 10px; color: red; text-shadow: 0px 0px 0px #000; -webkit-text-fill-color: transparent; } input::-webkit-input-placeholder, textarea::-webkit-input-placeholder { color: #ccc;

Get contentEditable caret index position

折月煮酒 提交于 2019-11-26 01:23:50
问题 I\'m finding tons of good, crossbrowser anwers on how to SET the cursor or caret index position in a contentEditable element, but none on how to GET or find its index... What I want to do is know the index of the caret within this div, on keyup . So, when the user is typing text, I can at any point know its cursor\'s index within the contentEditable element. EDIT: I\'m looking for the INDEX within the div contents (text), not the cursor coordinates. <div id=\"contentBox\" contentEditable=\

Carets in Regular Expressions

僤鯓⒐⒋嵵緔 提交于 2019-11-26 01:00:26
问题 Specifically when does ^ mean \"match start\" and when does it mean \"not the following\" in regular expressions? From the Wikipedia article and other references, I\'ve concluded it means the former at the start and the latter when used with brackets, but how does the program handle the case where the caret is at the start and at a bracket? What does, say, ^[b-d]t$ match? 回答1: ^ only means "not the following" when inside and at the start of [] , so [^...] . When it's inside [] but not at the

contenteditable, set caret at the end of the text (cross-browser)

岁酱吖の 提交于 2019-11-25 23:11:41
问题 output in Chrome : <div id=\"content\" contenteditable=\"true\" style=\"border:1px solid #000;width:500px;height:40px;\"> hey <div>what\'s up?</div> <div> <button id=\"insert_caret\"></button> I believe in FF it would look something like this: hey <br /> what\'s up? and in IE : hey <p>what\'s up?</p> unfortunately, there is no nice way of making it so that every browser inserts a <br /> instead of a div- or p-tag, or at least I couldn\'t find anything online. ANYWAY, what I am trying to do

How to get the caret column (not pixels) position in a textarea, in characters, from the start?

…衆ロ難τιáo~ 提交于 2019-11-25 22:17:29
问题 How do you get the caret position in a <textarea> using JavaScript? For example: This is| a text This should return 7 . How would you get it to return the strings surrounding the cursor / selection? E.g.: \'This is\', \'\', \' a text\' . If the word “is” is highlighted, then it would return \'This \', \'is\', \' a text\' . 回答1: With Firefox, Safari (and other Gecko based browsers) you can easily use textarea.selectionStart, but for IE that doesn't work, so you will have to do something like

How to set caret(cursor) position in contenteditable element (div)?

天涯浪子 提交于 2019-11-25 22:06:25
问题 I have this simple HTML as an example: <div id=\"editable\" contenteditable=\"true\"> text text text<br> text text text<br> text text text<br> </div> <button id=\"button\">focus</button> I want simple thing - when I click the button, I want to place caret(cursor) into specific place in the editable div. From searching over the web, I have this JS attached to button click, but it doesn\'t work (FF, Chrome): var range = document.createRange(); var myDiv = document.getElementById(\"editable\");