Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

235
Views
Cómo llamar a la función en keyup - Javascript

Estoy tratando de crear una salida de mathjax en un archivo png
He creado un JSFiddle aquí
Usé un código como el siguiente, tengo un código html como

 function myFunction(eqn){ window.MathJax = { jax: ["input/TeX", "output/SVG"], extensions: ["tex2jax.js", "MathMenu.js", "MathZoom.js"], showMathMenu: false, showProcessingMessages: false, messageStyle: "none", SVG: { useGlobalCache: false }, TeX: { extensions: ["AMSmath.js", "AMSsymbols.js", "autoload-all.js"] }, AuthorInit: function() { MathJax.Hub.Register.StartupHook("End", function() { var mj2img = function(texstring, callback) { var input = texstring; var wrapper = document.createElement("div"); wrapper.innerHTML = input; var output = { svg: "", img: ""}; MathJax.Hub.Queue(["Typeset", MathJax.Hub, wrapper]); MathJax.Hub.Queue(function() { var mjOut = wrapper.getElementsByTagName("svg")[0]; mjOut.setAttribute("xmlns", "http://www.w3.org/2000/svg"); // thanks, https://spin.atomicobject.com/2014/01/21/convert-svg-to-png/ output.svg = mjOut.outerHTML; var image = new Image(); image.src = 'data:image/svg+xml;base64,' + window.btoa(unescape(encodeURIComponent(output.svg))); image.onload = function() { var canvas = document.createElement('canvas'); canvas.width = image.width; canvas.height = image.height; var context = canvas.getContext('2d'); context.drawImage(image, 0, 0); output.img = canvas.toDataURL('image/png'); callback(output); }; }); } mj2img(eqn, function(output){ const t = document.getElementById("target"); const i = document.createElement('img'); i.src = output.img; t.append(i); }); }); } }; } (function(d, script) { script = d.createElement('script'); script.type = 'text/javascript'; script.async = true; script.onload = function() { // remote script has loaded }; script.src = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js'; d.getElementsByTagName('head')[0].appendChild(script); }(document));
 <textarea onkeyup="myFunction(this.value)"></textarea> <div id="target"></div>

¿Cómo mostrar la imagen cuando keyup un formulario que contiene un área de texto?

Aquí hay una versión funcional del código anterior al dar un valor directo.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

patrón estándar para detector de eventos keyup

 document.getElementById("target").onkeyup = function() {funName()};

Según su problema específico. No estoy muy seguro de dónde quieres aplicarlo.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!