如何获取点击的元素's的ID
How to get the clicked element's ID
我想检索被点击元素的ID(在'onclick;event.上
<script>
function myFunction(element)
{
var $id = element.id;
$($id).click(function() {
$.get('ajaxTestSrvlt?test=1', function(responseText) {
$('#firstName').val(responseText); with the response text.
});
});
};
</script>
这就是调用该函数的元素。我想从上面的脚本中获得这个raw的ID。只有当我直接将id设置为"clickableRow"时,这才有效。"ID"将动态更改
<tr id="clickableRow" style="cursor: pointer;" class='clickable-row' data-href="#" data-toggle="modal" data-target="#editModal" onclick="myFunction(this)">
不需要内联事件处理程序
<tr id="clickableRow" style="cursor: pointer;" class='clickable-row' data-href="#" data-toggle="modal" data-target="#editModal">
然后
jQuery(function () {
$('.clickable-row').click(function () {
var $this = $(this),
id = this.id;
$.get('ajaxTestSrvlt?test=1', function (responseText) {
$('#firstName').val(responseText);
//here `id` is the id of the clicked tr
});
});
})
试试这个
function myFunction(ele)
{
var id=$(ele).attr("id");
$('#'+id).click(function() {
//code here
});
}
只需使用此
onclick="myFunction(this.id)
代替
onclick="myFunction(this)
在我的功能上获取您的id
function myFunction(getid) {
alert(getid);
}
相关文章:
- 选择不带选择器的元素,仅使用元素ID
- 从元素id中获取值,而不是从javascript中的名称中获取值
- 如何将第二个元素id注入到网站元素中
- 将 JavaScript 元素 ID 传递给 PHP 或 Form Variable
- 如何在 javascript 中将表单中的元素 id 值作为数组传递
- 用于指定元素 ID 的正确 JavaScript 语法是什么
- 如何从 jQuery 中的 ajax 函数中的类访问元素 ID
- JavaScript获取多个已知元素ID
- 使用ng repeat时元素ID重复
- 在使用onblur进行输入评估时,是否可以获得单击对象的元素id
- JQuery通过变量标识元素id:多个表行
- 当元素ID包含美元符号时,Javascript中的getElementByid.当ID包含美元符号时,
- 我得到未捕获的类型错误:无法读取属性'选项'即使定义了元素id,也为null
- 元素id未被接受为函数参数
- 使用jquery获取类元素id
- 如何在没有任何元素id的情况下检索表中的文本内容
- jquery按类确定元素id
- 获取元素ID并传递到函数中
- 使用jquery获取元素id
- JavaScript文档.getElementById(“id”)和元素id属性