Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/463.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jQuery/Javascript:更改achor标记的单击_Javascript_Jquery_Events - Fatal编程技术网

jQuery/Javascript:更改achor标记的单击

jQuery/Javascript:更改achor标记的单击,javascript,jquery,events,Javascript,Jquery,Events,我想更改锚的onclick事件,但我无法使用javascript使其工作。 以下是我正在尝试的: document.getElementById(“CommCo”).onclick=“GetComments”(+id+)” 编辑:对不起,大家,但我要求更改它的值,而不是事件处理程序本身。无论如何,感谢大家。通过javascript分配onclick属性需要一个函数: document.getElementById("CommCo").onclick = function() { GetComme

我想更改锚的
onclick
事件,但我无法使用javascript使其工作。 以下是我正在尝试的:
document.getElementById(“CommCo”).onclick=“GetComments”(+id+)”


编辑:对不起,大家,但我要求更改它的值,而不是事件处理程序本身。无论如何,感谢大家。

通过javascript分配
onclick
属性需要一个函数:

document.getElementById("CommCo").onclick = function() { GetComments(this.id); };
工作示例


如果计划使用jQuery,以下是绑定事件的语法:

$('#CommCo').bind('click', function(e) {

    // 'this' in here is the element that was clicked

    GetComments(this.id);

});
  • “#CommCo”
    是jquery中的ID选择器
  • 您还可以使用方法
    .click()
    ,该方法在内部调用
    .bind('click',…)

通过javascript分配
onclick
属性需要一个函数:

document.getElementById("CommCo").onclick = function() { GetComments(this.id); };
工作示例


如果计划使用jQuery,以下是绑定事件的语法:

$('#CommCo').bind('click', function(e) {

    // 'this' in here is the element that was clicked

    GetComments(this.id);

});
  • “#CommCo”
    是jquery中的ID选择器
  • 您还可以使用方法
    .click()
    ,该方法在内部调用
    .bind('click',…)
尝试使用JQuery

var idvar = 1234; // Some ID
$("#CommCO").bind("click", {id:idvar}, function(event) { getComments(event.data.id); });
祝你好运

试试JQuery

var idvar = 1234; // Some ID
$("#CommCO").bind("click", {id:idvar}, function(event) { getComments(event.data.id); });
祝你好运

在jQuery中:

$('#CommCo').on('click', function() {
    GetComments($(this).attr('id'));
});
在jQuery中:

$('#CommCo').on('click', function() {
    GetComments($(this).attr('id'));
});

问题是用jquery标记的,因此,我将在此框架中演示如何做到这一点:

$("#CommoCo").click( function() { GetComments( this.id ); } ); 

问题是用jquery标记的,因此,我将在此框架中演示如何做到这一点:

$("#CommoCo").click( function() { GetComments( this.id ); } ); 

如果只是属性的值,请使用

document.getElementById("CommCo").setAttribute('onclick', 'GetComments('+id+');');
如果要更改“单击”事件的事件处理程序,请执行以下操作

document.getElementById("CommCo").addEventListener( 'click', function() { 
   GetComments( this.id ); 
}); 
如果您想在jQuery中执行此操作

$('#CommCo').bind( 'click', function (ev) { 
   GetComments(id); 
}); 

如果只是属性的值,请使用

document.getElementById("CommCo").setAttribute('onclick', 'GetComments('+id+');');
如果要更改“单击”事件的事件处理程序,请执行以下操作

document.getElementById("CommCo").addEventListener( 'click', function() { 
   GetComments( this.id ); 
}); 
如果您想在jQuery中执行此操作

$('#CommCo').bind( 'click', function (ev) { 
   GetComments(id); 
}); 

你说的“改变”是什么意思?是否要将其转换为jQuery语法?您使用了“jQuery”标记,但在代码中没有使用任何有关jQuery的内容。让它工作是什么意思?你希望发生什么事?什么不起作用?你说的“改变”是什么意思?是否要将其转换为jQuery语法?您使用了“jQuery”标记,但在代码中没有使用任何有关jQuery的内容。让它工作是什么意思?你希望发生什么事?什么不起作用了?谢谢。我想每个人都误解了我的问题。我要求更改值,而不是处理程序。现在它确实发生了完美的变化!谢谢我想每个人都误解了我的问题。我要求更改值,而不是处理程序。现在它确实发生了完美的变化!