Javascript-форум (https://javascript.ru/forum/)
-   jQuery (https://javascript.ru/forum/jquery/)
-   -   Конструкция не пашет в функции , а в событии работает (https://javascript.ru/forum/jquery/8067-konstrukciya-ne-pashet-v-funkcii-v-sobytii-rabotaet.html)

FRIE 05.03.2010 10:37

Конструкция не пашет в функции , а в событии работает
 
вот код
function DeleteMessage(middel,recipient,authoruid) {

jConfirm('Удалить сообщение?', 'Confirmation Dialog', function(r) {
if(r){
$.post('index.php?action=mail&delmessage=true', { middel: middel, recipient: recipient, authoruid: authoruid});

$('this').closest('tr').remove();
}

});
}
</script>

<input type=button class='11px' style='background: yellow repeat-x left; width:35px; height:17px; line-height:12px;' title='Удалить это сообщение' value='Уд' onclick='DeleteMessage($mid[$i], $recipient[$i], $authoruid[$i]);'>

$('this').closest('tr').remove(); не работает, а если я его ставлю прямо в событие вот так

<input type=button class='11px' style='background: yellow repeat-x left; width:35px; height:17px; line-height:12px;' title='Удалить это сообщение' value='Уд' onclick=$('this').closest('tr').remove();>

то всё пашет замечательно. подскажите где ошибка?

Achilles_sm 05.03.2010 11:38

Ошибка в использовании this.

http://javascript.ru/tutorial/object/thiskeyword

Цитата:

В отличие от PHP, Java, C++ и т.п, значение this в javascript не привязывается статически ни к какому объекту, а зависит от контекста вызова.

А ты в первом случае обращаешься к this из функции jConfirm()...


Часовой пояс GMT +3, время: 18:21.