<script>
function connectMaterToSlave(masterClass, slaveClass, relatedClassBeginsWith) {
const connection = ({target, target: { classList }}) => {
if (!classList.contains(masterClass)) return;
for (const className of classList) {
if (className.startsWith(relatedClassBeginsWith)) {
document.querySelectorAll(`input.${slaveClass}.${className}`).forEach(
input => input.value = target.value
);
return;
}
}
};
document.addEventListener('input', connection, true);
return () => {
document.removeEventListener('input', connection, true);
}
}
connectMaterToSlave('master', 'slave', 'price_');
</script>
<input class="autosubmit master price_45s_1_fat" size="1" type="text" name="price" value="400">
<input class="autosubmit master price_45s_3_fat" size="1" type="text" name="price" value="430">
<input class="autosubmit master price_45s_20_fat" size="1" type="text" name="price" value="400">
<br/>........<br/>
<input class="autosubmit slave price_45s_1_fat" size="1" type="text" name="price" value="400">
<input class="autosubmit slave price_45s_3_fat" size="1" type="text" name="price" value="430">
<input class="autosubmit slave price_45s_20_fat" size="1" type="text" name="price" value="400">
Вот без jq.
....вот что из этого сгенерил чатгпт в jq, если надо:
function connectMasterToSlave(masterClass, slaveClass, relatedClassBeginsWith) {
$(document).on('input', '.' + masterClass, function(event) {
var $target = $(event.target);
var classList = $target.attr('class').split(/\s+/);
$.each(classList, function(index, className) {
if (className.startsWith(relatedClassBeginsWith)) {
$('input.'+ slaveClass + '.' + className).val($target.val());
}
});
});
}