jquery在某些情况下启用/禁用文本框 [英] jquery for enable/disable textbox in some condition

查看:55
本文介绍了jquery在某些情况下启用/禁用文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 任何一个请提供代码 jquery。 


如果 tbfirstper == 100 那么 tbsecondnominee,tbsecondper, tbthitdnominee,tbthirdper 启用。
如果 tbfirstper< 100; 那么 tbsecondnominee,tbsecondper 启用,
如果 tbfirstper + tbsecondper< 100,那么 tbthitdnominee ,tbthirdper 启用,

请帮助我如何 编写代码





i尝试下面的代码,但是当页面加载时,所有文本框都启用..







< script type =text / javascript>



 $( #tbsecondnominee,#tbsecondper,#tbthitdnominee,#tbthirdper) .attr(  disabled true  ); 
$(document).ready(function(){
// if tbfirstper == 100然后tbsecondnominee,tbsecondper,tbthitdnominee,tbthirdper未启用。
// 如果tbfirstper< 100;然后tbsecondnominee,tbsecondper启用,
// 如果tbfirstper + tbsecondper< 100,然后tbthitdnominee,tbthirdper启用
$( #tbfirstper,#tbsecondnominee,#tbsecondper, #tbthitdnominee,#tbthirdper)。blur(function(){
$( # tbsecondnominee,#tbsecondper,#tbthitdnominee,#tbthirdper)。attr( disabled true );
var v1 = $( #tbfirstper)。val(),
v2 = $(< span class =code-string> #tbsecondper)。val();
if (!isNaN(v1)){
if (parseInt(v1) , 10 )== 100 ){
$( #tbsecondnominee,#tbsecondper,#tbthitdnominee,#tbthirdper)。attr( disabled true );
}
else if (parseInt(v1, 10 < 100 ){
$(< span class =code-string> #tbthitdnominee,#tbthirdper)。attr( disabled true );
$( #tbsecondnominee,#tbsecondper)。attr( disabled false );
}
if (!isNaN(v2)){
if ((parseInt(v2, 10 )+ parseInt(v1, 10 ))== 100 ){
$( #tbthitdnominee,#tbthirdper )。attr( disabled);
}
else if ((parseInt(v2, 10 )+ parseInt(v1, 10 ))< < span class =code-digit> 100
){
$( #tbthitdnominee, #tbthirdper)。attr( disabled);
}
}
}
});
});
< / script >

解决方案

#tbsecondnominee,#tbsecondper,#tbthitdnominee,#tbthirdper)。attr( disabled true );


(document).ready(function(){
// 如果tbfirstper == 100则tbsecondnominee,tbsecondper,tbthitdnominee,tbthirdper未启用。
// 如果tbfirstper< 100;那么tbsecondnominee,tbsecondper启用,
// 如果tbfirstper + tbsecondper< 100,则tbthitdnominee,tbthirdper is enable


#tbfirstper,#tbsecondnominee,#tbsecondper,#tbthitdnominee,#tbthirdper)。模糊(function(){


Any one please provide me the code for jquery.


    if tbfirstper==100 then tbsecondnominee,tbsecondper,tbthitdnominee,tbthirdper is not enable.
    If tbfirstper <100;then tbsecondnominee,tbsecondper is enable,
    if tbfirstper+tbsecondper<100, then tbthitdnominee,tbthirdper is enable,

 please help me how to write the code



i have try the bellow code but when page load then all textboxes are enable..



<script type="text/javascript">

$("#tbsecondnominee,#tbsecondper,#tbthitdnominee,#tbthirdper").attr("disabled", true);
$(document).ready(function () {
    // if tbfirstper==100 then tbsecondnominee,tbsecondper,tbthitdnominee,tbthirdper is not enable.
    // If tbfirstper <100;then tbsecondnominee,tbsecondper is enable,
    // if tbfirstper+tbsecondper<100, then tbthitdnominee,tbthirdper is enable
    $("#tbfirstper,#tbsecondnominee,#tbsecondper,#tbthitdnominee,#tbthirdper").blur(function () {
        $("#tbsecondnominee,#tbsecondper,#tbthitdnominee,#tbthirdper").attr("disabled", true);
        var v1 = $("#tbfirstper").val(),
        v2 = $("#tbsecondper").val();
        if (!isNaN(v1)) {
            if (parseInt(v1, 10) == 100) {
                $("#tbsecondnominee,#tbsecondper,#tbthitdnominee,#tbthirdper").attr("disabled", true);
            }
            else if (parseInt(v1, 10) < 100) {
                $("#tbthitdnominee,#tbthirdper").attr("disabled", true);
                $("#tbsecondnominee,#tbsecondper").attr("disabled", false);
            }
            if (!isNaN(v2)) {
                if ((parseInt(v2, 10) + parseInt(v1, 10)) == 100) {
                    $("#tbthitdnominee,#tbthirdper").attr("disabled", true);
                }
                else if ((parseInt(v2, 10) + parseInt(v1, 10)) < 100) {
                    $("#tbthitdnominee,#tbthirdper").attr("disabled", false);
                }
            }
        }
    });
});
  </script>

解决方案

("#tbsecondnominee,#tbsecondper,#tbthitdnominee,#tbthirdper").attr("disabled", true);


(document).ready(function () { // if tbfirstper==100 then tbsecondnominee,tbsecondper,tbthitdnominee,tbthirdper is not enable. // If tbfirstper <100;then tbsecondnominee,tbsecondper is enable, // if tbfirstper+tbsecondper<100, then tbthitdnominee,tbthirdper is enable


("#tbfirstper,#tbsecondnominee,#tbsecondper,#tbthitdnominee,#tbthirdper").blur(function () {


这篇关于jquery在某些情况下启用/禁用文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆