如何使文本框进行编辑?

时间:2018-11-21 18:29:40

标签: javascript html css textbox

我想添加一个文本框以将令牌输入我的HTML代码:

  <script src="https://sdk.scdn.co/spotify-player.js"></script>
  <script>
    window.onSpotifyWebPlaybackSDKReady = () => {
      const token = 'token1' ;
      const player = new Spotify.Player({ 	
        name: 'Web Playback SDK Quick Start Player',
        getOAuthToken: cb => { cb(token); }
      });

      // Error handling
      player.addListener('initialization_error', ({ message }) => { console.error(message); });
      player.addListener('authentication_error', ({ message }) => { console.error(message); });
      player.addListener('account_error', ({ message }) => { console.error(message); });
      player.addListener('playback_error', ({ message }) => { console.error(message); });

      // Playback status updates
      player.addListener('player_state_changed', state => { console.log(state); });

      // Ready
      player.addListener('ready', ({ device_id }) => {
        console.log('Ready with Device ID', device_id);
      });

      // Not Ready
      player.addListener('not_ready', ({ device_id }) => {
        console.log('Device ID has gone offline', device_id);
      });

      // Connect to the player!
      player.connect();
    };
  </script>

它应该在我写它的地方有一个令牌,但是我想添加一个文本框,巫婆会把它放进去。任何想法,我尝试了很多其他教程,但没有用

1 个答案:

答案 0 :(得分:0)

<input type="text" name="oauth-token" />

<script>
let token = document.getElementsByName("oauth-token")[0].value;
</script>

token将保存输入到表单元素中的值。根据需要展开和消毒。