【问题标题】:Using javascript to make one field required or other not working使用 javascript 使一个字段成为必填字段或其他字段无效
【发布时间】:2017-01-22 16:33:49
【问题描述】:

您好我正在尝试使用以下 javascript 来制作移动或固定电话我正在使用 .net webforms,并且我有以下脚本,但它不起作用我已经为我的控件提供了所需的客户端 ID 并在脚本标签之间加载脚本页面底部的其他脚本运行良好,所以不是我的页面有问题,而是这个脚本。

我正在通过以下方式将我的控件附加到脚本

   <ClientSideEvents Validation="function(s, e) { OnLandLineValdiate(s, e); }" ValueChanged="function(s, e) {   OnUpdateControlValue(s, e); }" />

根据我使用的控制套件,哪些是正确的方法

function OnLandLineValidate(s,e)     {
     if (!e.isValid)
        return;

      var landLine = landLineEdit.GetValue();
      e.isValid = mobileEdit == null || landLine == null;
      e.errorText = "Land Line or Mobile is required."

 }


function OnMobileValidate(s, e) {
 if (!e.isValid)
            return;
        var mobileEdit = mobileEdit.GetValue();

        e.isValid = mobileEdit == null || landLine == null;
        e.errorText = "Land Line or Mobile is required."

 }

我想要发生的是,如果填写了mobile,那么如果填写了座机,那么这两个条件都满足了,那么这两个条件也满足了?。

【问题讨论】:

  • 你应该修正错别字:我认为应该是Validate,而不是Valdiate,并且在第二个函数中,你写了两次landLine == null...
  • 第二个函数没有两次landine==null
  • jQuery 永远是答案
  • 这个项目很长一段时间都不允许改变我害怕@RaisingAgent
  • 好吧,“不要改变它,如果它至少部分运行” - EA Games

标签: javascript asp.net webforms devexpress


【解决方案1】:

两者都是否定条件,因此您应该使用 != 运算符而不是 == 运算符。

e.isValid =(!(mobile == null && landline == null))

【讨论】:

    猜你喜欢
    • 2019-07-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-01
    相关资源
    最近更新 更多