Javascript div框中php上的Jquery不工作
我有一个主php,通过下拉列表将php加载到div框中。 加载的php包含一个表。其中有一个jquery,它在单击行时发出警报Javascript div框中php上的Jquery不工作,javascript,php,jquery,Javascript,Php,Jquery,我有一个主php,通过下拉列表将php加载到div框中。 加载的php包含一个表。其中有一个jquery,它在单击行时发出警报 $(document).ready(function() { $('#newsTable tr').click(function(){ var clickedId = $(this).children('td:first').text(); alert(clickedId); }); }); 但在加载到div后,脚本不会触发replac
$(document).ready(function() {
$('#newsTable tr').click(function(){
var clickedId = $(this).children('td:first').text();
alert(clickedId);
});
});
但在加载到div后,脚本不会触发replace
(document).ready(function() {
与
使用事件委派来附加事件。允许我们将单个事件侦听器附加到父元素,该事件侦听器将为与选择器匹配的所有子体触发,无论这些子体现在存在还是将来添加
$(document).ready(function() {
$(document).on('click','#newsTable tr',function(){
var clickedId = $(this).children('td:first').text();
alert(clickedId);
});
}); // End
事件授权有点问题。尝试使用以下代码:
$('id_Or_Class_container_hold_the_php_data').on('click', 'tr', function(){
var clickedId = $(this).children('td:first').text();
alert(clickedId);
});
试试这个
jQuery(document).ready(function($) {
$('#newsTable tr').click(function(){
var clickedId = $(this).children('td:first').text();
alert(clickedId);
});
});
我认为您需要使用实时查询,而不是您的点击事件,您可以使用以下内容
$('#newsTable tr')。在('click',function()上使用以下代码。我认为它工作正常
$(document).ready(function() {
$("#newsTable").on('click','tr',function(){
var clickedId = $(this).children('td:first').text();
alert(clickedId);
});
});
它是在just div中加载还是脚本标记作为包装器出现?虽然此代码片段可能会解决此问题,但确实有助于提高您文章的质量。请记住,您将在将来回答读者的问题,而这些人可能不知道您提出代码建议的原因。
$(document).ready(function() {
$("#newsTable").on('click','tr',function(){
var clickedId = $(this).children('td:first').text();
alert(clickedId);
});
});