简体   繁体   English

如何正确使用 html 中文本框的值 请帮助我

[英]How to correctly use values from textboxes in html pls help me

I wanted to use values from textboxes but failed so i tried with constant values and now I am getting a NAN error.我想使用文本框中的值但失败了,所以我尝试使用常量值,现在我收到了 NAN 错误。 I am showing my result in a label btw.顺便说一句,我在标签中显示了我的结果。

function myFunction() {
  var translength = 2400
  var transSpacing = 150
  var transEndOverhang = 75
  var transStartOverhang = 75

  var longLength = 6000
  var LongSpacing = 150
  var LongStartOverhang = 75
  var LongEndOverhang = 75

  if (transSpacing != 0)
    document.getElementById('longAmount').value = ((transLength - transStartOverhang - transEndOverhang) / transSpacing) + 1;
  document.getElementById('longAmount').innerHTML = document.getElementById('longAmount').value
  if (document.getElementById('longAmount').value > 0 && transStartOverhang + ((document.getElementById('longAmount').value - 1) * transSpacing) + transEndOverhang < transLength)
    document.getElementById('longAmount').value = longAmount + 1;
  document.getElementById('longAmount').innerHTML = document.getElementById('longAmount').value
}

You're mixing innerHTML and value for the same id.您正在为相同的 id 混合innerHTMLvalue If that id is a textbox you should use .value .如果那个 id 是一个文本框,你应该使用.value Also, to convert strings (the text from the textarea) you can use parseInt() or parseFloat() .此外,要转换字符串(来自 textarea 的文本),您可以使用parseInt()parseFloat()

// Here you're taking a bunch of variables and sets the textareas value
document.getElementById('longAmount').value = ((transLength - transStartOverhang - transEndOverhang) / transSpacing) + 1;

// Makes no sense (textarea doesn't have a innerHTML)
document.getElementById('longAmount').innerHTML = document.getElementById('longAmount').value;

// document.getElementById('longAmount').value is a string here
if (document.getElementById('longAmount').value > 0 && transStartOverhang + ((document.getElementById('longAmount').value - 1) * transSpacing) + transEndOverhang < transLength)
    document.getElementById('longAmount').value = longAmount + 1; // longAmount is undefined.

// Again, makes no sense.
document.getElementById('longAmount').innerHTML = document.getElementById('longAmount').value;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 请帮我绘制谷歌图表 Codeigniter - Pls Help me Draw Google Chart Codeigniter jQuery:如何使用2个文本框进行1个HTML预览 - Jquery : How to use 2 textboxes to make 1 HTML preview 如何将HTML文本框值从一个域复制到另一个域的文本框? - How can I copy HTML textbox values from one domain to another domain's textboxes? 如何从asp.net中动态生成的html文本框中获取值 - How to get the values from dynamically generated html textboxes in asp.net 将单元格值显示在HTML表格MySQL数据的文本框中 - Show cell values into textboxes from HTML table MySQL data Google图表未加载请帮助我 - Google Charts doesn't load Pls help me React 应用程序的 Webpack 再生器编译问题,请帮助我 - Webpack regenerator compile issue for React app, help me pls 我想在任何 javascript 或 servlet 的帮助下使用 html 文本框从文本文件中读取和替换字符串? - I want to read and replace string from text file using html textboxes with the help of any javascript or servlet? jQuery - 如何将数组从 PHP 发送到 HTML 文本框 - jQuery - How to send an array from PHP to HTML textboxes 如何通过单击按钮将从内容脚本中检索到的值存储到文本框中 - How to store the values retrieved from content script into textboxes with a button click
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM