Ich habe folgende jQuery Variable:
var confirmbox=$('<div></div>')
.data({'defaultText': 'This action cannot be reversed. Are you sure you wish to do this?',
'defaultButtons': { Yes : function() { $(this).dialog('close');},
No : function() { $(this).dialog('close');}
}
});
Ich möchte confirmbox.html()
-confirmbox.data('defaultText')
einzustellen.
confirmbox.html(confirmbox.data('defaultText'));//this works
confirmbox.html($(this).data('defaultText'));//this fails. Why?
Und die gleiche Fehler Syntax funktioniert jetzt hier:
confirmbox.dialog({
autoOpen: false,
modal: true,
buttons: $(this).data('defaultButtons'),
close: function(){
$(this).html($(this).data('defaultText')); //working here. Why?
$(this).dialog('option','buttons',$(this).data('defaultButtons'));
}
});
Ich denke, dass ich nicht verstehe, was $(this)
in bestimmten Kontexten bezieht. Wie kann ich es sagen?
Sollte dies nicht 'return $ (this) .data ('defaultText') sein;'? –
@Rocket, yup. Fest. –