jscript 'type' attribute

jscript 'type' attribute

本文关键字:attribute type jscript      更新时间:2023-09-26

我试图在javascript上实现以下逻辑。

如果类型为"bankAccountTypeId",则使用$(field.className)获取与字段具有相同className的所有字段,然后使用.each循环遍历每个结果,将field.value与$(this).val()进行比较,如果它们不同,则使用alert显示错误消息(失败则中断)。

函数onChange_productListField(字段,类型){

  if (HimmsJSUtil.elementHasClass(field, 'DC')) {
        var allProductGroupFields = $(".DC."+type);
        var value = field.value;
        if (field.options) {
              value = HimmsJSUtil.getSelectedDropDownOption(field);
        }
        allProductGroupFields.each(function(index) {
              if ($(this).attr("id") != field.id
                          && !$(this).val()) {
                    $(this).val(value);
              }
        });
  } else {

        /* implement the logic here */
  }

}

我的问题是,在这个逻辑中,type属性将如何工作?

首先让我们明确jscript不是javascript,代码中的"type"不是属性,只是函数的一个参数。

var allProductGroupFields = $(".DC."+type);

上一行使用jQuery来选择一组同时具有类"DC"answers"bankAccountTypeId"的元素,其中类型为"bankAccountType Id"。这样的代码可以用在这样的结构中:

<div class="whatever">
    <input type="text" class="DC bankAccountTypeId" />
    <input type="text" class="DC userId" />
    <a href="http://stackoverflow.com/questions/1041344">
        jQuery multiple class selector
    <a>
</div>

额外:
对于像这样的结构

<div class="DC">
    <input type="text" class="bankAccountTypeId" />
    <input type="text" class="userId" />
    <a href="http://stackoverflow.com/questions/3767512">
        jQuery class within class selector
    <a>
</div>

选择器行必须更改为

var allProductGroupFields = $(".DC ."+type);