Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/83.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函数,而不是说hello_Javascript_Jquery - Fatal编程技术网

我希望这个脚本触发一个javascript函数,而不是说hello

我希望这个脚本触发一个javascript函数,而不是说hello,javascript,jquery,Javascript,Jquery,我找到了一个有效的脚本,现在请记住,我对JQuery一点都不了解。我想要这个脚本: document.getElementById("id_of_button").onclick = function() {clickFunction()}; function clickFunction() {alert("hello");} $("#id_of_textbox").keyup(function(event){ if(event.keyCode === 13){ $(

我找到了一个有效的脚本,现在请记住,我对JQuery一点都不了解。我想要这个脚本:

document.getElementById("id_of_button").onclick = function() {clickFunction()};

function clickFunction() {alert("hello");}

$("#id_of_textbox").keyup(function(event){
    if(event.keyCode === 13){
        $("#id_of_button").click();
    }
});
触发此函数而不是创建hello弹出窗口

document.location.href = 'http://cse.google.com/cse?cx=009002930969338329916:kta6o_isob0&q=' + escape(document.getElementById('search-box').value)

不完全清楚,但根据有限的信息:

function clickFunction() {
  var mylink = escape(document.getElementById('search-box').value);
  document.location.href = 'http://cse.google.com/cse?cx=009002930969338329916:kta6o_isob0&q=' + mylink;
}
看起来这整件事可以写成:

$("#id_of_button").on('click', function() {
  var mylink = escape($('#search-box').value);
  document.location.href = 'http://cse.google.com/cse?cx=009002930969338329916:kta6o_isob0&q=' + mylink;
});

$("#id_of_textbox").keyup(function(event) {
  if (event.keyCode === 13) {
    $("#id_of_button").trigger('click');
  }
});

下面是你想要的代码

<input type="text" id="search-box">
<button id="id_of_button">Search</button>

<script type="text/javascript">
  document.getElementById("id_of_button").onclick = function() {clickFunction()};

  function clickFunction() {
    document.location.href =
        'https://cse.google.com/cse?cx=009002930969338329916:kta6o_isob0&q=' +
      escape(document.getElementById('search-box').value)
    }

  $("#id_of_textbox").keyup(function(event){
      if(event.keyCode === 13){
          $("#search-box").click();
      }
  });
</script>

你在问如何使用文本编辑器?不,我想让jquery脚本触发另一个函数。你已经有了这些代码。您可以使用clickFunction中所需的代码替换警报,也可以将其放置到keyup处理程序中。此外,还可以将其放置在第三个函数中,并在keyup处理程序中调用该函数,而不是.click.Include中的.ifevent.keyCode==13中的代码行{`如果你想用keycode 13@kallus在keyup上使用它仍然不起作用,就把我带到search.html?而不是执行代码行它不起作用,只把我发送到search.html?而不是我想要的页面
$("#id_of_textbox").click(function () {
    document.location.href = 'http://cse.google.com/cse?cx=009002930969338329916:kta6o_isob0&q=' + escape($('#search-box').val())
});

$(document).keypress(checkKey);

function checkKey(e) {
    switch (e.keyCode) {
    case 13:
       document.location.href = 'http://cse.google.com/cse?cx=009002930969338329916:kta6o_isob0&q=' + escape($('#search-box').val())
        break;
    }
}