我有主页 index.php
并且在这个页面上单击按钮我正在使用 ajax 加载 url.php。
在 url.php 中我有 文本框
。我希望当用户在这个 texbox 中输入内容时,它下面显示的按钮变得可见。
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>
索引.php
正文部分:
<script>
$("#text").keypress( function() {
document.getElementById("b1").style.display = "block";
console.log( "Handler for .keypress() called." );
});
</script>
但是当我转到文本框并单击它时,文本框没有出现。我也试过
blur
和 focus
代替 keypress
但没有变化。
要使用 ajax 加载 url.php,我有以下代码:
<input type="button" id="load_url" value="Load url.php" />
$("#load_url").click(function(){
$.ajax({
url:"url.php",
success:function(response) {
$("#view_port").html(response);
$("#load_url").hide();
}
});
});
最佳答案
将您的 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" />
或
<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 ) {...});
});
希望对您有所帮助。
关于javascript - 由ajax调用加载的页面中文本框上的Jquery按键事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19353986/