来自输入属性 jQuery 的数组
array from input attribute jQuery
>需要检查每个输入是否具有属性inArray,然后显示此输入文件否则隐藏
我的网页代码
<label class="priceswrapper" tour_type="reg, div">Price
<input name="adult_cost" type="text"/>
</lable>
<label class="priceswrapper" tour_type="reg, div">Price
<input name="kids_cost" type="text"/>
</lable>
<label class="priceswrapper" tour_type="div">Price
<input name="intro_dive" type="text"/>
</lable>
<label class="priceswrapper" tour_type="div">Price
<input name="pro_dive" type="text"/>
</lable>
<label class="priceswrapper" tour_type="qud">Price
<input name="quad_price" type="text"/>
</lable>
j查询代码
jQuery(document).ready(function() {
$('.priceswrapper').each(function(){
var data = 'reg';
var types = [$(this).attr('tour_type')];
if ($.inArray(data, types) !== -1) {
$(this).show();
}else {
$(this).hide();
}
});
});
尝试如下:
<script>
jQuery(document).ready(function() {
$('.priceswrapper').each(function(){
var data = 'reg';
var types = $(this).attr('tour_type').split(',');// you should get string fron here.
console.log(types);
if ($.inArray(data, types) !== -1) {
$(this).show();
}else {
$(this).hide();
}
});
});
</script>
<label class="priceswrapper" tour_type="reg, div">Price
<input name="adult_cost" type="text"/>
</lable>
<label class="priceswrapper" tour_type="reg, div">Price
<input name="kids_cost" type="text"/>
</lable>
<label class="priceswrapper" tour_type="div">Price
<input name="intro_dive" type="text"/>
</lable>
<label class="priceswrapper" tour_type="div">Price
<input name="pro_dive" type="text"/>
</lable>
<label class="priceswrapper" tour_type="qud">Price
<input name="quad_price" type="text"/>
</lable>
你可以
使用它。小提琴
.HTML
<label class="priceswrapper" data-type="reg, div">Price
<input name="adult_cost" type="text"/>
</label>
<label class="priceswrapper" data-type="reg, div">Price
<input name="kids_cost" type="text"/>
</label>
<label class="priceswrapper" data-type="div">Price
<input name="intro_dive" type="text"/>
</label>
<label class="priceswrapper" data-type="div">Price
<input name="pro_dive" type="text"/>
</label>
<label class="priceswrapper" data-type="qud">Price
<input name="quad_price" type="text"/>
</label>
jQuery
var data = 'reg';
$('.priceswrapper').each(function(idx, obj) {
var types = $(this).data('type').split(/,'s+/);
console.log(types);
console.log($.inArray(data, types));
if ($.inArray(data, types) !== -1) {
$(obj).show();
} else {
$(obj).hide();
}
});
相关文章:
- 按键,值到数组:jQuery
- 数组数组jquery,json到数组
- 从数组jquery中基于子字符串的移除项
- 从数组jQuery中删除一组项
- 如何在数组jQuery中查找字符串的一部分
- 当输入字段名称在数组jquery中时序列化表单
- 打乱图像数组jquery
- 在数组 jQuery 中查找值
- 循环遍历多维数组 jQuery
- 在数组 jQuery 中查找特定的字符串模式
- 随机选择带有删除项的数组(jQuery)
- 在数组中附加值数组 - jquery
- 从数组 Jquery 中获取下拉列表的选定索引
- 删除相同值数组 Jquery
- 如何从数组 jquery 中删除特定值
- 将 2D 数组 jQuery Post 发送到 Java Servlet
- 获取数组jQuery中元素的索引
- 正在从会话数组Jquery Ajax中删除项
- 在GET请求中绑定复杂对象的数组-jquery.praram()传统标志
- 获取空对象数组jquery post