按键上的搜索栏输入未运行功能进行搜索

时间:2021-04-02 18:10:32

标签: javascript html

我有一个搜索栏,可以在 google 上搜索输入,而且工作正常。我试图在按下 Enter 键时添加一个按键输入功能来运行搜索,但它不起作用我添加了一个 console.log 来调试我的函数 df['date'] = pd.to_datetime(df['date']) df['date']=df['date'].map(dt.datetime.toordinal) 是否正在运行并且它通过了我不明白它是怎么回事虽然没有在按键输入上搜索谷歌。当按下搜索图标时,它会起作用。任何帮助表示赞赏。提前致谢。

searchGoogle
function doSomething(event) {
  console.log(event.keyCode);
  if (event.keyCode == 13) {
    searchGoogle();
  }
}

function searchGoogle() {
  var input = document.getElementById("googleSearchInput");
  document.getElementById("googleSearchButton").href =
    (("https://www.google.com/search?q=") + (document.getElementById("googleSearchInput").value));
  console.log(input.value);
}
.form-group {
  width: 50%;
  position: absolute;
  top: 3%;
  left: 4%;
  z-index: 1;
}

.form-control:focus {
  border-color: #ff80ff;
  box-shadow: 0px 1px 1px rgba(0, 0, 0, 0.075) inset, 0px 0px 8px rgba(255, 100, 255, 0.5);
}

.form-group img {
  width: 4%;
  height: auto;
  position: absolute;
  top: 50%;
  right: 1%;
  margin-right: 1%;
}

1 个答案:

答案 0 :(得分:1)

您无法按 Enter 键,因为您没有点击链接的事件。 换句话说 - 您为链接分配了新的 href 但没有点击它。

这里为您更新了代码

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <stdbool.h>

int main( void )
{
    char str[100];

retry_input:

    //prompt user for input
    printf( "Enter number: " );

    //read one line of input
    if ( fgets( str, sizeof str, stdin ) == NULL )
    {
        fprintf( stderr, "input error!\n" );
        exit( EXIT_FAILURE );
    }

    //if newline character exists, remove it
    str[strcspn(str,"\n")] = '\0';

    //this variable keeps track of the number of digits encountered
    int num_digits = 0;

    //this variable specifies whether we have encountered a decimal point yet
    bool found_decimal_point = false;

    //inspect the string one character at a time
    for ( char *p = str; *p!='\0'; p++ )
    {
        if ( *p == '.' )
        {
            if ( found_decimal_point )
            {
                printf( "encountered multiple decimal points!\n" );
                goto retry_input;
            }

            found_decimal_point = true;
        }
        else if ( isdigit( (unsigned char)*p ) )
        {
            num_digits++;
        }
        else if ( *p != '+' && *p != '-' )
        {
            printf( "encountered unexpected character in input!\n" );
            goto retry_input;
        }
        else if ( p - str != 0 )
        {
            printf(
                "sign characters (+/-) are only permitted at the start "
                "of the string!\n"
            );
            goto retry_input;
        }
    }

    if ( found_decimal_point )
    {
        //input is floating-point

        printf( "The input is float and has %d digits.\n", num_digits );
    }
    else
    {
        //input is integer

        printf( "The input is integer and has %d digits.\n", num_digits );
    }

    return EXIT_SUCCESS;
}