【问题标题】:How to get properties of Kendo element in javascript如何在javascript中获取剑道元素的属性
【发布时间】:2014-06-23 09:43:36
【问题描述】:

我在 Razor 视图页面上有几个 Kendo NumericTextBoxes 和一个事件处理程序:

@Html.Kendo().NumericTextBoxFor(model => model.SignedNumericTextBox1).Step(0.25f).Events(e => e.Change("ChangeSignedNumericTextBox1"))
@Html.Kendo().NumericTextBoxFor(model => model.SignedNumericTextBox2).Step(0.25f).Events(e => e.Change("ChangeSignedNumericTextBox2"))
@Html.Kendo().NumericTextBoxFor(model => model.SignedNumericTextBox3).Step(0.25f).Events(e => e.Change("ChangeSignedNumericTextBox3"))

<script>
function ChangeSignedNumericTextBox1() {
    var val = this.value()
    alert(this.name);
    if (val > 0) {
        $("#SignedNumericTextBox1").kendoNumericTextBox({ format: "+##.##", decimals: 2 });
    }
    else {
        $("#SignedNumericTextBox1").kendoNumericTextBox({ format: "##.##", decimals: 2 });
    }
}

function ChangeSignedNumericTextBox2() {
    var val = this.value()
    alert(this.name);
    if (val > 0) {
        $("#SignedNumericTextBox2").kendoNumericTextBox({ format: "+##.##", decimals: 2 });
    }
    else {
        $("#SignedNumericTextBox2").kendoNumericTextBox({ format: "##.##", decimals: 2 });
    }
}

function ChangeSignedNumericTextBox3() {
    var val = this.value()
    alert(this.name);
    if (val > 0) {
        $("#SignedNumericTextBox3").kendoNumericTextBox({ format: "+##.##", decimals: 2 });
    }
    else {
        $("#SignedNumericTextBox3").kendoNumericTextBox({ format: "##.##", decimals: 2 });
    }
}
</script>

有没有办法在我的 JavaScript 中引用数字文本框,这样我只需要一个 ChangeSignedNumericTextBox 函数?

【问题讨论】:

    标签: javascript jquery razor kendo-ui


    【解决方案1】:

    这应该会有所帮助:

    <script>
      function changeme()
      {
    
        var myId = '#' + this._form.context.id;
        var val = $(myId).val();
    
        if (val > 0) {
             $(myId).kendoNumericTextBox({ format: "+##.##", decimals: 2 });
        }
        else {
             $(myId).kendoNumericTextBox({ format: "##.##", decimals: 2 });
        }
    
      }
    
    </script>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-07-06
      • 2021-05-04
      • 2021-07-20
      • 2017-10-23
      • 1970-01-01
      • 1970-01-01
      • 2021-09-17
      • 2021-08-07
      相关资源
      最近更新 更多