是否有任何理由不应该这样做(避免使用隐藏字段来存储临时信息)?为简洁起见,我使用jQuery语法,但这是一个常见的JavaScript问题。在全局的Javascript变量中保存临时表单信息
function editComments() {
window.currentComments = $('#commentsTextBox').val();
$('#commentsTextBox').removeAttr("readonly");
}
function cancelEditComments() {
$('#commentsTextBox').val(window.currentComments);
$('#commentsTextBox').attr("readonly", "readonly");
}
我知道全局变量一般被认为是不好的做法,但是真的有这个问题吗?
请不要回答/评论与“全局变量是邪恶的”,除非你可以给出一个理由/解释。
的“removeAttr”功能只注重第一个参数。 – Pointy 2010-07-05 15:35:52
是的,这是一个错字。现在更正。 – fearofawhackplanet 2010-07-05 15:48:58