Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript ';onclick';不使用EJS和节点_Javascript_Html_Node.js_Ejs - Fatal编程技术网

Javascript ';onclick';不使用EJS和节点

Javascript ';onclick';不使用EJS和节点,javascript,html,node.js,ejs,Javascript,Html,Node.js,Ejs,我正在使用EJS制作一个小的Express应用程序,并试图获得一个onclick函数来传递所选选项的值。我有两个问题,如下所示。非常感谢您的帮助 EJS供参考: <select class="dropdown" onclick="<%= console.log(this) %>"> <option disabled selected value> -- Select Environment -- </option> <% en

我正在使用EJS制作一个小的Express应用程序,并试图获得一个
onclick
函数来传递所选选项的值。我有两个问题,如下所示。非常感谢您的帮助

EJS供参考:

<select class="dropdown" onclick="<%= console.log(this) %>">
    <option disabled selected value> -- Select Environment -- </option>
    <% environments.forEach(env => { %>
        <option value="<%= env %>"><%= env %></option>
    <% }) %>
</select>

这将立即在服务器上执行
console.log(This)
,并将值打印到页面源

如果查看呈现的HTML,您将看到
onclick=“undefined”
,因为这就是
console.log
返回的内容


您希望将原始文本
console.log(this)
呈现到页面,以便浏览器将其视为(客户端)Javascript代码。

谢谢!我之前尝试过,但
console.log()
不起作用(我的节点--inspect由于某种原因不是节点检查),但我将其切换为alert,它显示的值正确!谢谢在浏览器中运行的;您需要查看浏览器的控制台。
{ console: [Getter],
  DTRACE_NET_SERVER_CONNECTION: [Function],
  DTRACE_NET_STREAM_END: [Function],
  DTRACE_HTTP_SERVER_REQUEST: [Function],
  DTRACE_HTTP_SERVER_RESPONSE: [Function],
  DTRACE_HTTP_CLIENT_REQUEST: [Function],
  DTRACE_HTTP_CLIENT_RESPONSE: [Function],
  COUNTER_NET_SERVER_CONNECTION: [Function],
  COUNTER_NET_SERVER_CONNECTION_CLOSE: [Function],
  COUNTER_HTTP_SERVER_REQUEST: [Function],
  COUNTER_HTTP_SERVER_RESPONSE: [Function],
  COUNTER_HTTP_CLIENT_REQUEST: [Function],
  COUNTER_HTTP_CLIENT_RESPONSE: [Function],
  global: [Circular],
  process:
   process {
     title: '  - nodemon  app.js',
     version: 'v8.9.3',
     moduleLoadList:
      [ <stuff> ],
     versions: { http_parser: '2.7.0',
  node: '8.9.3',
  v8: '6.1.534.48',
  uv: '1.15.0',
  zlib: '1.2.11',
  ares: '1.10.1-DEV',
  modules: '57',
  nghttp2: '1.25.0',
  openssl: '1.0.2n',
  icu: '59.1',
  unicode: '9.0',
  cldr: '31.0.1',
  tz: '2017b' },
     arch: 'x64',
     platform: 'win32',
     release:
      { <stuff> },
     env:
      { <stuff> },
     pid: 8532,
     features:
      { <stuff> },
     _needImmediateCallback: true,
     execPath: 'C:\\Program Files\\nodejs\\node.exe',
     debugPort: 9229,
     _startProfilerIdleNotifier: [Function: _startProfilerIdleNotifier],
     _stopProfilerIdleNotifier: [Function: _stopProfilerIdleNotifier],
     _getActiveRequests: [Function: _getActiveRequests],
     _getActiveHandles: [Function: _getActiveHandles],
     reallyExit: [Function: reallyExit],
     abort: [Function: abort],
     chdir: [Function: chdir],
     cwd: [Function: cwd],
     umask: [Function: umask],
     _kill: [Function: _kill],
     _debugProcess: [Function: _debugProcess],
     _debugPause: [Function: _debugPause],
     _debugEnd: [Function: _debugEnd],
     hrtime: [Function: hrtime],
     cpuUsage: [Function: cpuUsage],
     dlopen: [Function: dlopen],
     uptime: [Function: uptime],
     memoryUsage: [Function: memoryUsage],
     binding: [Function: binding],
     _linkedBinding: [Function: _linkedBinding],
     _setupDomainUse: [Function: _setupDomainUse],
     _events:
      { warning: [Function],
        newListener: [Function],
        removeListener: [Function],
        SIGWINCH: [Array] },
     _rawDebug: [Function],
     _eventsCount: 4,
     domain: null,
     _maxListeners: undefined,
     _fatalException: [Function],
     _exiting: false,
     assert: [Function],
     config: { target_defaults: [Object], variables: [Object] },
     emitWarning: [Function],
     nextTick: [Function: nextTick],
     _tickCallback: [Function: _tickCallback],
     _tickDomainCallback: [Function: _tickDomainCallback],
     stdout: [Getter],
     stderr: [Getter],
     stdin: [Getter],
     openStdin: [Function],
     exit: [Function],
     kill: [Function],
     argv0: 'node',
     mainModule:
      Module {
        id: '.',
        exports: [Object],
        parent: null,
        filename: <stuff>,
        loaded: true,
        children: [Array],
        paths: [Array] },
     _immediateCallback: [Function: processImmediate] },
  Buffer:
   { [Function: Buffer]
     poolSize: 8192,
     from: [Function],
     alloc: [Function],
     allocUnsafe: [Function],
     allocUnsafeSlow: [Function],
     isBuffer: [Function: isBuffer],
     compare: [Function: compare],
     isEncoding: [Function],
     concat: [Function],
     byteLength: [Function: byteLength],
     [Symbol(node.isEncoding)]: [Function] },
  clearImmediate: [Function],
  clearInterval: [Function],
  clearTimeout: [Function],
  setImmediate: { [Function: setImmediate] [Symbol(util.promisify.custom)]: [Function] },
  setInterval: [Function],
  setTimeout: { [Function: setTimeout] [Symbol(util.promisify.custom)]: [Function] } }
<%= console.log(this) %>