我有元素列表,当我从列表中选择元素时,来自代码的“值”正在改变。
<div class="drop-down-cont zi-5 fleft">
<input class="dd-input" id="packaging_item_packaging_name" name="packaging_item[packaging_name]" title="Packaging Type" type="hidden" value="PX">
<a class="drop-down-link item-qnt" href="#" id="packaging_item_packaging_name_link">Pallet</a>
<div class="drop-down pic" style="visibility: visible; ">
<div class="blue-tarr"></div>
<div class="drop-down-list-cont w400">
<div class="drop-down-list first pt-cases w100p" id="cases_results_"><ul class="w100p">
<li id="PX" class="selected">
<a href="javascript:void(0)">Pallet</a>
</li>
<li id="PB">
<a href="javascript:void(0)">Pallet Box</a>
</li>
<li id="PLP">
<a href="javascript:void(0)">Peel pack</a>
</li>
</ul>
</div>
<div class="pic-cont h100p"><img alt="Package Image" src="/images/pi_new/32.jpg?1312107854"> </div>
</div>
<div class="remark">
A platform used to hold or transport unit loads.
</div>
<a class="submit-btn2 pt-choose-btn-" href="javascript:void(0)" id="pack_apply">Apply</a>
</div>
</div>
<table id="pallet_table" style="display:none;">
<tbody>
<tr>
<td>
stacking factor:
</td>
<td>
<input class="w44" id="packaging_item_stacking_factor" name="packaging_item[stacking_factor]" size="30" type="text" value="1">
</td>
</tr>
</tbody>
</table>
当我选择'值'为'PX'并执行此脚本
时,我想显示表格if ($('.dd-input').attr('value') == 'PX') {
$('#pallet_table').show();}
但这不是动态的。我如何处理此事件然后将值从'smth'更改为'PX'
答案 0 :(得分:0)
这可以解决您的问题(请参阅this jsfiddle):
jQuery('.dd-input').bind('change', function(){
if (jQuery(this).val() == 'PX'){
// do here whatever you need
$('#pallet_table').show();
}
});
但是,我没有看到您希望用户如何更改此字段的值(在您的代码中隐藏字段)。如果这是通过不同的脚本完成的,那么当前的方法可能不是最好的方法,你应该明确地调用某个函数而不是在值改变时这样做吗?