简体   繁体   中英

In-line script in IE11 not working

I have a simple in-line script in an html page:

  <script>
          function keyDown(event, inputId) {

              if (event.keyCode == 13) {
                  startSearch(inputId)
              }
          }

          function startSearch(inputId) {
              var searchText = document.getElementById(
                  inputId).value
              var newLocation =
                  `<%= clientAppUrl %>/search?searchString=${searchText}`

              window.location = newLocation
          }
      </script>

It is invoked from an input tag:

<input id='search1' onkeydown="keyDown(event, 'search1')" placeholder='Bla...' />

The script works perfectly in Chrome and Safari and on mobile devices but in IE11 it gives an error keyDown is undefined .

IE11 does not support templated strings , so it's likely that

var newLocation = `<%= clientAppUrl %>/search?searchString=${searchText}`

Is breaking the entire <script> block it's contained within, causing keyDown to not be present. You'll need to rewrite it to not use the interpolated string if you wish to support IE11.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM