ximada12342234 2023-04-22 17:36 采纳率: 0%
浏览 11

js变量引用HTML中文本框的value一直出错

html中搞了几个文本框,然后js中通过变量把文本框中手工输入的值取过来,一直不成功。
下面是html的代码,要引用的是J0的value(都是阿拉伯数字)

  <table id="bg2" border="0" cellpadding="0" cellspacing="0" style="margin: 0px;background-color: #800000;">
    <tr>
    <td id="selftable" class="attribute" width="280">   
        <table class="table1" border="1" cellpadding="0" cellspacing="0" bordercolor="#0079C2" height="160" width="280">
          <tr >
            <td width="50" height="20"><span style="color:#0F0">姓名</span></td>
            <td width="85" height="20">
              <span><input type="text" class="Input" id="X" size="8" style="width: 80px; height: 20px; font-size: 13pt; font-weight: 400; text-align:center;background-color:#EEEEEE" value="" name="X"></span>
            </td>
            <td width="50" height="20"><span style="color:#0F0">专属</span></td>
            <td width="50" height="20"><span style="color:#0F0">策略</span></td>
          </tr>
          <tr>
            <td width="50" height="20"><span>生命</span></td>
            <td id="X0" width="85" height="20"><span>0/0</span></td>
            <td id="A0" width="85" height="20"><span >0</span></td>
            <td width="85" height="20">
            <span><input type="text" class="Input" id="J0" size="8" style="width: 80px; height: 20px; font-size: 13pt; font-weight: 400; text-align:center;background-color:#EEEEEE" value="0" name="J0"></span>
            </td>
          </tr>

下面是js的代码,通过cj0变量来引用,一直不成功。求帮忙指点!

var cJ0 =0;
cj0 =document.getElementById('J0').value;

  • 写回答

2条回答 默认 最新

  • 创意程序员 2023-04-22 17:52
    关注

    html只是片段吧?
    js放什么位置了?
    使用表单form,input放表单中试试。

    评论

报告相同问题?

问题事件

  • 创建了问题 4月22日

悬赏问题

  • ¥100 关于python拓展屏使用pyautogui.screenshot无法截图的问题
  • ¥15 有偿求答 无导出权限怎么快速导出企业微信微文档
  • ¥15 求解答,怎么数码管中这么加入闹钟或者传感器,这应该怎么加入相应的代码
  • ¥15 scottplot5
  • ¥30 想问问这个建模怎么编程没有思路
  • ¥15 关于imageENview(ImageEN)中新建图层并根据鼠标位置添加图标
  • ¥100 用两台电脑局域联网进行MT5的EA参数优化,但是连接不上,日志提示:
  • ¥15 FastAPI报错: AsyncSession不是有效Pydantic类型
  • ¥50 这Mac系统提示虚拟内存不足,怎么解决
  • ¥15 Rs232电路无法收发数据,求帮助