Javascript GetElementById设置为null而不是int
我有一段代码,它只是获取一个id并将其分配给一个变量,因为某种原因,当它应该是php for循环中的整数时,通知id被设置为null javascriptJavascript GetElementById设置为null而不是int,javascript,php,jquery,html,Javascript,Php,Jquery,Html,我有一段代码,它只是获取一个id并将其分配给一个变量,因为某种原因,当它应该是php for循环中的整数时,通知id被设置为null javascript $(".pro_content_notification_remove").live('click', function (e) { var notification_id = document.getElementById(this); e.preventDefault(); $(this).parent().remove();
$(".pro_content_notification_remove").live('click', function (e) {
var notification_id = document.getElementById(this);
e.preventDefault();
$(this).parent().remove();
}))
php/html
<?php
foreach($notification_array as $key => $value){
echo '<div class="pro_content_notification_ele" id="'.$value.'">
<div class="pro_content_notification_image '.$notification_image_id.'"></div><!--end pro_content_notifications_image-->
<span class="pro_content_notification_text '.$viewed.'">'.$notification_text.'</span>
<div class="pro_content_notification_remove"></div><!--end pro_content_notification_remove-->
</div><!--end pro_content_notification_ele-->';
}
?>
我已经检查了数组和页面源,在pro_content_notification_ele的id中设置的$value肯定是1,那么为什么要设置null呢
感谢您的帮助
此
引用事件处理程序中的dom元素,因此使用this.id
获取元素的id
$(".pro_content_notification_remove").live('click', function (e) {
var notification_id = this.id;
e.preventDefault();
$(this).parent().remove();
});
注意:如果您使用的是jQuery>=1.7,请使用而不是.live()
此
引用事件处理程序中的dom元素,因此请使用此.id
获取元素的id
$(".pro_content_notification_remove").live('click', function (e) {
var notification_id = this.id;
e.preventDefault();
$(this).parent().remove();
});
注意:如果您使用的是jQuery>=1.7,请使用而不是.live()
此
引用事件处理程序中的dom元素,因此请使用此.id
获取元素的id
$(".pro_content_notification_remove").live('click', function (e) {
var notification_id = this.id;
e.preventDefault();
$(this).parent().remove();
});
注意:如果您使用的是jQuery>=1.7,请使用而不是.live()
此
引用事件处理程序中的dom元素,因此请使用此.id
获取元素的id
$(".pro_content_notification_remove").live('click', function (e) {
var notification_id = this.id;
e.preventDefault();
$(this).parent().remove();
});
注意:如果您使用的是jQuery>=1.7,请使用而不是.live()尝试使用
var notification_id = e.target.id;
或
或
而不是
var notification_id = document.getElementById(this);
试着用
var notification_id = e.target.id;
或
或
而不是
var notification_id = document.getElementById(this);
试着用
var notification_id = e.target.id;
或
或
而不是
var notification_id = document.getElementById(this);
试着用
var notification_id = e.target.id;
或
或
而不是
var notification_id = document.getElementById(this);
不使用
document.getElementById(this)
使用
不使用
document.getElementById(this)
使用
不使用
document.getElementById(this)
使用
不使用
document.getElementById(this)
使用
this
不是字符串,getElementById
应该返回一个HTMLNode
。您以一种奇怪的方式将jquery与“常规”js混合在一起this
不是字符串,而getElementById
应该返回一个HTMLNode
。你用一种奇怪的方式将jquery与'regular'js混合在一起这个
不是字符串,getElementById
应该返回一个HTMLNode
。你用一种奇怪的方式将jquery与'regular'js混合在一起这个
不是字符串,而getElementById
应该返回一个HTMLNode