目前,我使用jquery
.keyup 函数来检查是否已开始输入输入字段。然后启用按钮。否则,如果输入中没有文本禁用按钮。
问题:
如果键入输入的文字与此{{1}不匹配,我希望能够启用按钮,而不是键盘功能}}
然后,如果输入的文本匹配,则启用按钮
输入字段
$user['username']
脚本
<input type="text" id="input-user-<?php echo $user['username']; ?>" name="username" value="" class="form-control input-user" />
查看
<script>
$(document).ready(function(){
$('#button-delete-user-<?php echo $user['username']; ?>').attr('disabled', true);
$('#input-user-<?php echo $user['username']; ?>').keyup(function(){
if($(this).val().length !=0)
$('#button-delete-user-<?php echo $user['username']; ?>').attr('disabled', false);
else
$('#button-delete-user-<?php echo $user['username']; ?>').attr('disabled', true);
});
});
</script>
答案 0 :(得分:1)
喜欢这个吗?
$(function() {
$('.someInput').on('keyup',function() {
var username = "test";
if( $(this).val() == username ) {
$('.someButton').attr('disabled', false);
}
else {
$('.someButton').attr('disabled', true);
}
});
});
您可以在脚本中实现它,如下所示:
<?php if ($users) { ?>
<?php foreach ($users as $user) { ?>
....
<form role="form" action="<?php echo $action;?>" method="post" enctype="multipart/form-data" id="form_id">
<div class="form-group">
<input type="text" class="input-user" data-username="<?php echo $user['username']; ?>" name="username" value="" class="form-control input-user" />
<input type="hidden" name="user_id" value="<?php echo $user['user_id']; ?>" class="form-control" />
</div>
<div class="form-group text-center">
<button type="submit" class="button-delete-user" data-username="<?php echo $user['username']; ?>" class="btn btn-user-delete"><span class="text-danger">I understand the consequences, deleting this user</span></button>
</div>
</form>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
$(function() {
$('button.button-delete-user').attr('disabled', true);
$('.input-user').on('keyup',function() {
var username = $(this).data('username');
if( $(this).val() == username ) {
$('button[data-username="'+username+'"]').attr('disabled', false);
}
else {
$('button[data-username="'+username+'"]').attr('disabled', true);
}
});
});
答案 1 :(得分:1)
工作示例
library(ggbiplot)
require(ggplot2)
data(iris)
data <- data.frame(iris[,1:4])
ir.pca <- prcomp(data, center = TRUE, scale. = TRUE)
theta <- seq(0,2*pi,length.out = 100)
circle <- data.frame(x = cos(theta), y = sin(theta))
p <- ggplot(circle,aes(x,y)) + geom_path()
loadings <- data.frame(ir.pca$rotation,
.names = row.names(ir.pca$rotation))
p + geom_text(data=loadings,
mapping=aes(x = PC1, y = PC2, label = .names, colour = .names)) +
coord_fixed(ratio=1) +
labs(x = "PC1", y = "PC2")
$("#input-user").keyup(function(){
console.log($(this).val(), $(this).data("name"));
if($(this).val() == $(this).data("name"))
$("#button-delete-user").prop('disabled', false);
else
$("#button-delete-user").prop('disabled', true);
});