我有以下代码:
$('.update-title')
.change(function () {
$(this).prop('title', $('option:selected', this).prop('title'));
});
和这个HTML:
<select id="modal_TempRowKey_14" class="update-grid update-title">
...
...
</select>
<input id="modal_Title_14" class="update-grid" type="text" value="xx">
我有可能做到这一点,以便当.update-title更改时
然后将标题的值与匹配的编号一起输入到输入ID中。
因此,在这种情况下,
#modal_TempRowKey_14
标题将变为#modal_Title_14
值重要
我希望仅当要更改的元素以
modal_TempRowKey
开头时才会发生这种情况。是否可以将其放入更改块? 最佳答案
尝试
$('.update-title').on("change", function() {
var id = this.id.replace('modal_TempRowKey_', '');
$("#modal_Title_" + id).val( $(this).val() );
});