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

200
Views
Cómo obtener el valor de HTML interno con JavaScript en Asp.net Core 5 Ver

En primer lugar, pido disculpas por escribir en inglés, que puede no ser correcto.

En la vista del proyecto Asp.Net Core, quiero que innerHTML capture varias etiquetas Span, cada una representada por un bucle, usando JavaScript y muestre la suma de ellas en otra etiqueta. Pero solo puedo obtener el valor de una etiqueta con un nombre o ID específico y no puedo obtener el valor de innerHTML de varias etiquetas con un nombre.

gracias por tu guia

Bucle en la tabla de elementos:

 @foreach (var R in Model.Where(x => x.ReportRDId == show.ReportRDId)) { <tr> <td> <span>@R.CourseName</span> + <span>@R.SectionName</span> + <span name="test-@R.ReportDayName">@R.TestCount <span>تست </span> </span> + <span >@R.TimeCount <span>ساعت </span> </span> </td> </tr> }

Traté de hacer que el nombre de cada etiqueta fuera único usando un valor obtenido del bucle. El nombre de cada etiqueta es correcto, pero no puedo leer el nombre correctamente en JavaScript.

Mi código JavaScript:

 @foreach (var R in Model.GroupBy(x => x.ReportRDId).Select(x => x.FirstOrDefault())) { <script> //To display the sum of the tests var Total = document.getElementsByName("TotalTest-@R.ReportDayName"); //Tests innerHTML var test = document.querySelectorAll("[name='test-@R.ReportDayName']"); //loop in test variable var count = 0; console.log(test); test.forEach(e => { console.log(e.innerHTML); count += parseInt(e.innerHTML); Total.forEach(element => { element.innerHTML = count; }); }); </script> }

Hice estas cosas pero el resultado que obtuve fue incorrecto

Vista de inspección del navegador para una de las etiquetas (preste atención al valor de su nombre):

 <script> //To display the sum of the tests var Total = document.getElementsByName("TotalTest-&#x634;&#x646;&#x628;&#x647;"); //Tests innerHTML var test = document.querySelectorAll("[name='test-&#x634;&#x646;&#x628;&#x647;']"); //loop in test variable var count = 0; console.log(test); test.forEach(e => { console.log(e.innerHTML); count += parseInt(e.innerHTML); Total.forEach(element => { element.innerHTML = count; }); });
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Resolví el problema. Mi error fue usar solo @ R.ReportDayName en lugar de @ Html.Raw (@ R.ReportDayName).

La solución correcta (Atención a @Html.Raw(@R.ReportDayName) ):

 @foreach (var item in Model.GroupBy(x => x.ReportRDId).Select(x => x.FirstOrDefault()).Take(1)) { <text> //To display the sum of the tests var Total = document.getElementsByName("TotalTest-@Html.Raw(R.ReportDayName)"); //Tests innerHTML var test = document.querySelectorAll("[name='test-@Html.Raw(R.ReportDayName)']"); //loop in test variable var count = 0; console.log(test); test.forEach(e => { console.log(e.innerHTML); count += parseInt(e.innerHTML); Total.forEach(element => { element.innerHTML = count; }); }); </text> }
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!