如何响应包含其ID中指定字符串的输入文本元素的任何退出(模糊)?

时间:2021-10-13 07:32:21

I want to update an input text element when any of a specific category (based on ID) of other input text elements are exited. Specifically, when any of the following input text elements:

我希望在退出其他输入文本元素的任何特定类别(基于ID)时更新输入文本元素。具体来说,当以下任何输入文本元素时:

boxAmount1
boxAmount2
boxAmount3
boxAmount4
boxAmount5

...are exited/blurred, I want to update the input text element which has "boxGrandTotal" in its ID.

...退出/模糊,我想更新其ID中包含“boxGrandTotal”的输入文本元素。

I thought "contains" would help me, so tried this:

我认为“包含”会帮助我,所以尝试了这个:

$(document).on("blur", '[id:contains('boxAmount')]', function (e) {
    $('[id$=boxGrandTotal]').text([combined values of all "boxAmount" input texts]);
});

...but JSHint tells me "Missing name in function declaration" on the first line, and "Expected an assignment or function call and instead saw an expression" on the thrid and last line.

...但JSHint在第一行告诉我“函数声明中缺少名称”,并且在thrid和最后一行上“预期赋值或函数调用,而是看到一个表达式”。

What do I need to do to respond to all "boxAmount" blurs?

我需要做些什么来回应所有“boxAmount”模糊?

NOTE: I use the "id$=" jazz because the IDs I give the elements (such as "boxGrandTotal") end up being mangled by Sharepoint, which prepends a bunch of gobbledygook to the IDs.

注意:我使用“id $ =”爵士乐,因为我给予元素的ID(例如“boxGrandTotal”)最终被Sharepoint破坏,这会为ID添加一堆gobbledygook。

1 个解决方案

#1


2  

Use the attribute starts with or contains selector

使用属性开头或包含选择器

$(document).on("blur", '[id^="boxAmount"]', function (e) {

});

or

$(document).on("blur", '[id*="boxAmount"]', function (e) {

});

#1


2  

Use the attribute starts with or contains selector

使用属性开头或包含选择器

$(document).on("blur", '[id^="boxAmount"]', function (e) {

});

or

$(document).on("blur", '[id*="boxAmount"]', function (e) {

});