onclick中返回的函数是否有html元素?

时间:2015-10-12 17:04:50

标签: javascript

好吧,就像标题一样。

例如,我有类似的东西:

$('.tags span').click(function(){
var html= $('.text').text();
var dd= html.replace(html[html.lastIndexOf('@')],'<span class="tag"contenteditable="true">'+$(this).text()+'</span>&nbsp')
$('.text').html(dd);
})

有没有这样做?这个功能包含'this'还是其他什么?我不想在这里使用jQuery。

1 个答案:

答案 0 :(得分:3)

默认情况下不包含对调用元素(this)的引用。你可以这样称呼它:

<input type="submit" value="some value" onclick="return name(this)" />

然后更改您的函数以使用该参数:

function name(elem){