0
我想要访问按钮的ID,当我写入PHP变量javascript代码创建错误“未定义”的值。如何使用javascript onclick()获取元素的属性值?
function update_profile(){ $(function() {
var element = $(this);
var update_id = element.attr("id");
var infoo = 'updated_id=' + update_id;
document.getElementsByClassName('test')[0].innerHTML=infoo;
});
}
按钮代码:
<button data-toggle="modal" data-target=".bs-example-modal-lg" onclick="update_profile()" class="btn-xs btn-warning " id='<?php echo $user_rec[1]; ?>' >Update</button>
首先,我不认为你需要用'$(函数(){'和关闭它'});' – Walk
删除'$(函数(){})'并改变'document.getElementsByClassName('test')[0] .innerHTML = infoo;'到'$(“。test”)。first()。html(infoo);'或者更好:'$(function(){ $(“。btn-warning”)。on(“click”,function(){$(“。test”)。first()。html(this.id);});});' – mplungjan