根据javascript的值更改值

时间:2014-12-05 06:05:38

标签: javascript jquery html

我需要根据文本框的值更改标签。我尝试了下面的代码,但它没有改变。我认为这是因为我没有对我的文本框有任何价值,所以如果有人知道实现这一目标的最佳方式,请告诉我。 =)

function changeval(){
  var x = document.getElementById("sff").value;
  document.getElementById("jffx").innerHTML = x;
}

$(document).ready(function(){
$("#state").change(function(){
    if($(this).val() == 'AL'){
        $("#entity").change(function(){
            if($(this).val() == 'LP'){
                    $('#sff').val('$186.00');
                    $('#osf').val('$119.00');
                    $("#desc").hide();
            }else ($(this).val() == 'LLC'){
                $('#sff').val('$186.00');
                $('#osf').val('$99.00');
                $("#desc").show();
                $("#alLLC").show();
}
<input type="text" id="sff" placeholder="$0.00" value="" onchange="changeval()"/>
<label id="jffx"></label>

1 个答案:

答案 0 :(得分:0)

您正在通过javascript更改文本字段的值,因此您还需要从那里更改标签。

function changeval(){
  var x = document.getElementById("sff").value;
  document.getElementById("jffx").innerHTML = x;
}

$(document).ready(function(){
$("#state").change(function(){
    if($(this).val() == 'AL'){
        $("#entity").change(function(){
            if($(this).val() == 'LP'){
                    $('#sff').val('$186.00');
                    $('#osf').val('$119.00');
                    $("#desc").hide();
            }else ($(this).val() == 'LLC'){
                $('#sff').val('$186.00');
                $('#osf').val('$99.00');
                $("#desc").show();
                $("#alLLC").show();
            }
            changeval(); //you need to call the function here also.
        });
     }
  });
});

尝试以上代码。

相关问题