Formulas are checked for correct input. It is necessary under the formulas to indicate the symbol ^ position where there is an incorrect input.
(a+b) - (ab) (a+b - (ab ^ ^ Formulas are checked for correct input. It is necessary under the formulas to indicate the symbol ^ position where there is an incorrect input.
(a+b) - (ab) (a+b - (ab ^ ^ Just check the number of open and closed brackets. If the numbers do not match, then there is an error somewhere. But the function finds only one error.
The error display function is taken from @Sergiks.
$('input').on('change', function() { var value = this.value; var opened = 0; var last = 0; for(var i=0, sp=value.split(""); i < sp.length; i++) { if(sp[i] == "(") { last = i; opened++; } if(sp[i] == ")"){ last = i; opened--; } if(opened < 0) { show_error(last); break; } } if(opened != 0) { show_error(last); } }); function show_error(sym_no) { alert(sym_no); } <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input> (ab) , a - () b , ab + - () - SergiksAs regards the placement of pointers under the line, it is easily solved by relative / absolute positioning. <span>^</span> inserted in the line in front of the desired place and moves down to the line height.
Suppose you somehow learned that errors are in positions 14 and 6 (the order is not important):
placeMarks(14,6); function placeMarks() { var el = document.getElementById("code") ,html = el.innerText.trim() ,insert = '<span class="here">^</span>' ,places = Array.prototype.slice.call(arguments).sort((a,b)=>ab) ,pieces = [] ,i ,j = 0 ; for(i=0; i<places.length;i++) { pieces.push( html.slice(j,places[i])); j = places[i]; } pieces.push( html.slice(j)); el.innerHTML = pieces.join(insert); } #code {font-size:16px;font-family:Courier New, monospace;position:relative} .here { position:absolute; top: 16px; } <div id="code">a+b+c ) * (ab /(ac)</div> You need to add an element containing ^ with absolute position and set it to some coordinates. I understand the question so much - how to calculate these coordinates.
The solution is shamanic: we create 2 spans with a font similar to where your formulas are written. In the 1st span, we add a character through <BR> - the same number on which line you have a place to which you need to specify. In the 2nd span we add the last line before the character - which you want to point to. And then get the coordinates like this:
var coordinates = { x: span2.offsetWidth, y: span1.offsetHeight }; I did not see any other way to determine the coordinates of a symbol.
Source: https://ru.stackoverflow.com/questions/539326/
All Articles
(a)+b - (a)-b. Where should be the closing bracket in the formula(a + b - a - b? - Sergiks