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
包含在函数中,并在成功部分调用该函数。尝试将idtext
更改为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');
});
}
});
});