vs.code.value无法被智能感知识别

时间:2019-03-20 22:46:05

标签: javascript html input intellisense

我对javascript很陌生,但是在工作时,我试图找出一种方法来获取用户输入到html输入文本框中的文本,但是由于某种原因,vs代码无法识别所需的intellisense去做这个。 [我的html代码:

java.net.BindException: Address in use (Bind failed)
    at java.net.PlainSocketImpl.socketBind(Native Method) ~[na:1.8.0_151]
    at java.net.AbstractPlainSocketImpl.bind(AbstractPlainSocketImpl.java:387) ~[na:1.8.0_151]
    at java.net.Socket.bind(Socket.java:644) ~[na:1.8.0_151]
    at org.apache.ftpserver.impl.IODataConnectionFactory.createDataSocket(IODataConnectionFactory.java:309) [ftpserver-core-1.1.1.jar:1.1.1]
    at org.apache.ftpserver.impl.IODataConnectionFactory.openConnection(IODataConnectionFactory.java:257) [ftpserver-core-1.1.1.jar:1.1.1]
    at org.apache.ftpserver.command.impl.LIST.execute(LIST.java:115) [ftpserver-core-1.1.1.jar:1.1.1]
    at org.apache.ftpserver.impl.DefaultFtpHandler.messageReceived(DefaultFtpHandler.java:211) [ftpserver-core-1.1.1.jar:1.1.1]
    at org.apache.ftpserver.listener.nio.FtpHandlerAdapter.messageReceived(FtpHandlerAdapter.java:62) [ftpserver-core-1.1.1.jar:1.1.1]
    at org.apache.mina.core.filterchain.DefaultIoFilterChain$TailFilter.messageReceived(DefaultIoFilterChain.java:858) [mina-core-2.0.16.jar:na]
    at org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextMessageReceived(DefaultIoFilterChain.java:542) [mina-core-2.0.16.jar:na]
    at org.apache.mina.core.filterchain.DefaultIoFilterChain.access$1300(DefaultIoFilterChain.java:48) [mina-core-2.0.16.jar:na]
    at org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1.messageReceived(DefaultIoFilterChain.java:947) [mina-core-2.0.16.jar:na]
    at org.apache.ftpserver.listener.nio.FtpLoggingFilter.messageReceived(FtpLoggingFilter.java:85) [ftpserver-core-1.1.1.jar:1.1.1]
    at org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextMessageReceived(DefaultIoFilterChain.java:542) [mina-core-2.0.16.jar:na]
    at org.apache.mina.core.filterchain.DefaultIoFilterChain.access$1300(DefaultIoFilterChain.java:48) [mina-core-2.0.16.jar:na]
    at org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1.messageReceived(DefaultIoFilterChain.java:947) [mina-core-2.0.16.jar:na]
    at org.apache.mina.core.filterchain.IoFilterEvent.fire(IoFilterEvent.java:74) [mina-core-2.0.16.jar:na]
    at org.apache.mina.filter.logging.MdcInjectionFilter.filter(MdcInjectionFilter.java:135) [mina-core-2.0.16.jar:na]
    at org.apache.mina.filter.util.CommonEventFilter.messageReceived(CommonEventFilter.java:70) [mina-core-2.0.16.jar:na]
    at org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextMessageReceived(DefaultIoFilterChain.java:542) [mina-core-2.0.16.jar:na]
    at org.apache.mina.core.filterchain.DefaultIoFilterChain.access$1300(DefaultIoFilterChain.java:48) [mina-core-2.0.16.jar:na]
    at org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1.messageReceived(DefaultIoFilterChain.java:947) [mina-core-2.0.16.jar:na]
    at org.apache.mina.filter.codec.ProtocolCodecFilter$ProtocolDecoderOutputImpl.flush(ProtocolCodecFilter.java:398) [mina-core-2.0.16.jar:na]
    at org.apache.mina.filter.codec.ProtocolCodecFilter.messageReceived(ProtocolCodecFilter.java:234) [mina-core-2.0.16.jar:na]
    at org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextMessageReceived(DefaultIoFilterChain.java:542) [mina-core-2.0.16.jar:na]
    at org.apache.mina.core.filterchain.DefaultIoFilterChain.access$1300(DefaultIoFilterChain.java:48) [mina-core-2.0.16.jar:na]
    at org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1.messageReceived(DefaultIoFilterChain.java:947) [mina-core-2.0.16.jar:na]
    at org.apache.mina.core.filterchain.IoFilterEvent.fire(IoFilterEvent.java:74) [mina-core-2.0.16.jar:na]
    at org.apache.mina.core.session.IoEvent.run(IoEvent.java:63) [mina-core-2.0.16.jar:na]
    at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.runTask(OrderedThreadPoolExecutor.java:770) [mina-core-2.0.16.jar:na]
    at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.runTasks(OrderedThreadPoolExecutor.java:762) [mina-core-2.0.16.jar:na]
    at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.run(OrderedThreadPoolExecutor.java:704) [mina-core-2.0.16.jar:na]
    at java.lang.Thread.run(Thread.java:748) [na:1.8.0_151]

] 1

[

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <input type="text" id="first-input">
    <button id="submit-button">Submit</button>
    <script src="main.js" type="text/javascript"></script>
</body>
</html>

] 2

为了在输入文本元素中获取数据,该代码为.value,但是,当我开始输入“ .val-”时,唯一的VS代码推荐是.nodeValue。

no .value option, only .nodeValue

这意味着,为了得到我想要的,我使用的是vs代码的intellisense无法识别的命令。但是,即使intellisense找不到它,代码仍然可以按预期运行。

code is functional

是否需要安装或执行某些操作才能访问此信息?我担心还有很多其他事情无法识别,这会使学习这种语言更加困难。预先感谢

1 个答案:

答案 0 :(得分:0)

这是因为getElementById()不一定返回具有.value属性的元素。例如,它可以返回一个<div>元素。

为了使智能感知知道您将拥有.value属性,您必须使用JSDoc注释指示变量firstInput将成为<input>元素。像这样:

/**
 * @type HTMLInputElement
 */
let firstInput = document.getElementById('first-input');
/**
 * @type HTMLButtonElement
 */
let submitButton = document.getElementById('submit-button');

submitButton.onclick = function () {
  console.log(firstInput.value);
}

不要让您感到困惑,但是VSCode使用TypeScript增强其智能even for JavaScript code