<input class="y" id="imploding_feature3" type="hidden" name="product_labels_module[3][manual_products]" value=",,,,62,108,,45,">
<input class="y" id="imploding_feature4" type="hidden" name="product_labels_module[4][manual_products]" value=",,,,45,78,,26,">
我想获取用户输入的值,然后删除该值。例如,用户输入值45,然后它将删除文本框中的所有45,但其他值将提示,如何使用jquery呢?
检查此演示的输出,我认为它可以满足您的需求。
更新的脚本:
$('#removeProduct').on('click', function() {
var input = $('#productId').val();
// loop through each imploding_feature and remove value if exist
$('input[id^="imploding_feature"]').each(function(ndx, elem) {
var values = $(elem).val();
console.log('before =', values);
var valuesarray = values.split(',').map(function(val, ndx) {
return (val === input)?'':val;
}).join(',');
$(elem).val(valuesarray);
console.log('after =', valuesarray);
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" id="productId" value="">
<button id="removeProduct">
remove product id
</button>
<input class="y" id="imploding_feature3" type="hidden" name="product_labels_module[3][manual_products]" value=",,,,62,108,,45,">
<input class="y" id="imploding_feature4" type="hidden" name="product_labels_module[4][manual_products]" value=",,,,45,78,,26,">
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句