【发布时间】:2013-01-27 15:35:40
【问题描述】:
我有多个与条件选择相关的字段。如果 Condition 与其他输入字段不匹配,则与上述 div ID 中的样式(display:none)相关联并且匹配保持活动状态,则在上述 div ID 中设置(display:block)。 这是在drupal中,所以我无法控制它...所以这里是生成的示例--
<div id="edit-field-p1brp-price" class="field-type-text field-name-field-p1brp-price field-widget-text-textfield form-wrapper" style="display: block;">
<div id="field-p1brp-price-add-more-wrapper">
<div class="form-item form-type-textfield form-item-field-p1brp-price-und-0-value">
<label for="edit-field-p1brp-price-und-0-value">
<input id="edit-field-p1brp-price-und-0-value" class="text-full form-text required" type="text" maxlength="255" size="60" value="5,98,000" name="field_p1brp_price[und][0][value]">
</div>
</div>
</div>
<div id="edit-field-sspps-price" class="field-type-text field-name-field-sspps-price field-widget-text-textfield form-wrapper" style="display: none;">
<div id="field-sspps-price-add-more-wrapper">
<div class="form-item form-type-textfield form-item-field-sspps-price-und-0-value">
<label for="edit-field-sspps-price-und-0-value">
<input id="edit-field-sspps-price-und-0-value" class="text-full form-text required" type="text" maxlength="255" size="60" value="4,65,000" name="field_sspps_price[und][0][value]">
</div>
</div>
</div>
<div id="edit-field-sspr1br-price" class="field-type-text field-name-field-sspr1br-price field-widget-text-textfield form-wrapper" style="display: none;">
<div id="field-sspr1br-price-add-more-wrapper">
<div class="form-item form-type-textfield form-item-field-sspr1br-price-und-0-value">
<label for="edit-field-sspr1br-price-und-0-value">
<input id="edit-field-sspr1br-price-und-0-value" class="text-full form-text required" type="text" maxlength="255" size="60" value="3,98,000" name="field_sspr1br_price[und][0][value]">
</div>
</div>
</div>
我必须只获取上面 DIV 中 DISPLAY 为 BLOCK 的那个输入的值。我尝试使用以下可见的 DIV ID,但它没有返回并尝试使用以上 DIV ID 和值也没有发生(这是我尝试的最后一个代码)--
if (($("#edit-field-p1brp-price-und-0-value:block").length > 0)){
var price = $('#edit-field-p1brp-price-und-0-value').val();
}
if (($("#edit-field-sspps-price-und-0-value:visible").length > 0)){
var price = $('#dit-field-sspps-price-und-0-value').val();
}
if (($("#edit-field-sspr1br-price-und-0-value:visible").length > 0)){
var price = $('#edit-field-sspr1br-price-und-0-value').val();
}
更新---
我用于获取更改一个选择和警报的值的代码更新,但它只给出 NULL..
$(document).ready(function() {
var price = null;
$('div.form-item-field-membership-payment-type-und').change(function() {
$("#edit-field-p1brp-price-und-0-value, #edit-field-sspps-price-und-0-value, #edit-field-sspr1br-price-und-0-value").each(function() {
if($(this).is(':visible')) {
price = $(this).val();
alert(price);
}
});
alert(price);
});
});
【问题讨论】:
-
缩短这些 ID 将减少到客户端的总传输大小,从而加快页面速度。
-
这是drupal渲染条件字段表单元素的方式...
-
啊,那我相信你无能为力。但是,如果您查看您发布的 HTML,您会发现大约 80% 的 HTML 有效负载用于元素 ID。
标签: javascript jquery drupal