Javascript Jquery:单击操作前确认
我的表格中有一个复选框。我想在用户选中复选框之前请他确认。但是,勾选框后,“确认”消息会自动出现。我想这样做,用户可以“取消”,这就好像他从来没有选中框开始 这是我的密码:Javascript Jquery:单击操作前确认,javascript,jquery,ruby-on-rails,Javascript,Jquery,Ruby On Rails,我的表格中有一个复选框。我想在用户选中复选框之前请他确认。但是,勾选框后,“确认”消息会自动出现。我想这样做,用户可以“取消”,这就好像他从来没有选中框开始 这是我的密码: $( document ).ready(function() { $('.checkme').click(function(){ text_area_id = "#" + $(this).val(); if ($(text_area_id).attr('hidden')) { $(text_a
$( document ).ready(function() {
$('.checkme').click(function(){
text_area_id = "#" + $(this).val();
if ($(text_area_id).attr('hidden')) {
$(text_area_id).attr('hidden', false);
} else{
if ($(text_area_id).val() != '') {
if (confirm("Clear text for \'" + $(this).val().replace(/_/g, " ") + "\'?")) {
$(text_area_id).attr('hidden', true);
$(text_area_id).val('');
$(this).attr('checked', true);
$('.checkme').attr('checked', true);
}
} else {
$(text_area_id).attr('hidden', true);
$('.checkme').attr('checked', true);
}
}
});
注意“确认”框。我希望在点击复选框时出现,但在框实际被勾选之前
所以我想我正在寻找一个jquery函数,比如
.before_click(function(){ ...
而不是
.click(function(){ ...
或者类似的…?只需根据您的
确认布尔值设置checkbox的checked属性<代码>窗口。确认
返回true
或false
$(.checkme”)。在('click',函数(e){
var r=确认(“你确定吗?!”);
$(this.attr('checked',r));
})
Check me
只需根据您的确认值设置checkbox的checked属性<代码>窗口。确认
返回true
或false
$(.checkme”)。在('click',函数(e){
var r=确认(“你确定吗?!”);
$(this.attr('checked',r));
})
检查我