Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/434.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 ajax调用加载的页面中文本框上的Jquery按键事件_Javascript_Jquery_Ajax - Fatal编程技术网

Javascript ajax调用加载的页面中文本框上的Jquery按键事件

Javascript ajax调用加载的页面中文本框上的Jquery按键事件,javascript,jquery,ajax,Javascript,Jquery,Ajax,我有一个主页index.php,在这个页面上单击按钮,使用ajax在url.php中加载我 在url.php中,我有文本框。我想当用户在这个文本框中使用courser输入内容时,下面的按钮就会显示出来 url.php <input type="text" id="text" name="sent" contenteditable="true" style=" text-align: left; height: 30px; width:512px; " placeholder="Enter

我有一个主页
index.php
,在这个页面上单击按钮,使用ajax在url.php中加载我

在url.php中,我有
文本框
。我想当用户在这个文本框中使用courser输入内容时,下面的按钮就会显示出来

url.php

<input type="text" id="text" name="sent" contenteditable="true"  style=" text-align: left; height: 30px; width:512px; " placeholder="Enter URL ..."/></input>
<button id="b1" style="display:none" > Get Sentiment </button>

url.php
更改为:

<textarea id="text" name="sent" contenteditable="true" style=" text-align: left; height: 30px; width:512px; " placeholder="Enter URL ..."></textarea>
<input type="button" id="b1" style="display:none" value=" Get Sentiment" />
希望有帮助。

试试这个

<script type="text/javascript">
    $("#text").keypress( function() {
        $("#b1").show();
        console.log( "Handler for .keypress() called." );
    });
</script>

$(“#文本”).keypress(函数(){
$(“#b1”).show();
log(“调用了.keypress()的处理程序”);
});

我猜您忘记在AJAX加载后注册
按键事件了

    $( document ).ready( function(e) {
       $('#button').click(function(e) { // Clicking the button to load the url.php
          $('#somediv').load("url.php", function() { // loading the url.php
             $('#text').keypress(function(e) { // You are registering the keypress event listener after the ajax load
                 $('#b1').show('fast');
             });
          }
       });
   });

使用ajax加载url.php后,注册
keypress
事件。将
keypress
包含在函数中,并在成功部分调用该函数。尝试将id
text
更改为
textabc
并绑定到jquery中,然后尝试加载url.php。我已经有代码检查我更新的问题!谢谢你,但是我带的是我必须带的。我有一些特定的css样式要求,所以它是定制的css按钮。您不能在
中使用
class=“btn”
?然后使用
中的
.btn{display:none;//其他CSS规则}
对其进行样式化。
<input type="text" id="text" name="sent" contenteditable="true" style=" text-align: left; height: 30px; width:512px; " placeholder="Enter URL ..." />
<input type="button" id="b1" style="display:none" value=" Get Sentiment" />
$(document).ready( function() {
    $("#text").bind("keypress", function( e ) {...});
});
<script type="text/javascript">
    $("#text").keypress( function() {
        $("#b1").show();
        console.log( "Handler for .keypress() called." );
    });
</script>
    $( document ).ready( function(e) {
       $('#button').click(function(e) { // Clicking the button to load the url.php
          $('#somediv').load("url.php", function() { // loading the url.php
             $('#text').keypress(function(e) { // You are registering the keypress event listener after the ajax load
                 $('#b1').show('fast');
             });
          }
       });
   });