php 如何在HTML中指定索引jquery索引值

pinkon5k  于 2023-04-04  发布在  PHP
关注(0)|答案(1)|浏览(137)

请建议我该怎么做才能将jquery结果添加到我的html中。这是jquery的脚本。

success:function(data){
         $.each(JSON.parse(data), function(index, value){
         $.each(value.lineItems, function(index, item){
         console.log(item.totalTax);
        });
        });
}

输出为

{
    "data": {
        "lineItems": [{
            "customer": {
                "customerCode": {
                    "classCode": "DATA",
                    "isBusinessIndicator": false,
                    "value": "BOO1234"
                },
                "destination": {
                    "city": "hudew",
                    "country": "INDIA",
                    "postalCode": "201301",
                    "streetAddress1": "dwdwe",
                    "taxAreaId": "50591530"
                },
                "isTaxExempt": false,
                "taxRegistrations": []
            },
            "extendedPrice": 200.0,
            "fairMarketValue": 200.0,
            "product": {
                "value": "srvice123"
            },
            "quantity": {
                "unitOfMeasure": "EA",
                "value": 1.0
            },
            "seller": {
                "company": "Production",
                "taxRegistrations": []
            },
            "taxIncludedIndicator": false,
            "taxes": [{
                "calculatedTax": 12.0,
                "calculationRuleId": {
                    "salesTaxHolidayIndicator": false,
                    "userDefined": false,
                    "value": "v1262305"
                },
                "effectiveRate": 0.06,
                "exempt": 0.0,
                "imposition": {
                    "impositionId": "v1j2398",
                    "userDefined": false,
                    "value": "Sales and Use Tax"
                },
                "impositionType": {
                    "impositionTypeId": "v1",
                    "userDefined": false,
                    "value": "General Sales and Use Tax"
                },
                "inclusionRuleId": {
                    "salesTaxHolidayIndicator": false,
                    "userDefined": false,
                    "value": "v1280125"
                },
                "isService": false,
                "jurisdiction": {
                    "effectiveDate": "1900-01-01",
                    "expirationDate": "9999-12-31",
                    "jurisdictionId": "2398",
                    "jurisdictionType": "STATE",
                    "value": "INDIA"
                },
                "maxTaxIndicator": false,
                "nominalRate": 0.06,
                "nonTaxable": 0.0,
                "notRegisteredIndicator": false,
                "situs": "DESTINATION",
                "taxCollectedFromParty": "BUYER",
                "taxResult": "TAXABLE",
                "taxStructure": "SINGLE_RATE",
                "taxType": "SALES",
                "taxable": 200.0
            }, {
                "calculatedTax": 2.5,
                "calculationRuleId": {
                    "salesTaxHolidayIndicator": false,
                    "userDefined": false,
                    "value": "v1080547"
                },
                "effectiveRate": 0.0125,
                "exempt": 0.0,
                "imposition": {
                    "impositionId": "v1j3262",
                    "userDefined": false,
                    "value": "Local Sales and Use Tax"
                },
                "impositionType": {
                    "impositionTypeId": "v1",
                    "userDefined": false,
                    "value": "General Sales and Use Tax"
                },
                "inclusionRuleId": {
                    "salesTaxHolidayIndicator": false,
                    "userDefined": false,
                    "value": "v1287055"
                },
                "isService": false,
                "jurisdiction": {
                    "effectiveDate": "1900-01-01",
                    "expirationDate": "9999-12-31",
                    "jurisdictionId": "3262",
                    "jurisdictionType": "COUNTY",
                    "value": "ORANGE"
                },
                "maxTaxIndicator": false,
                "nominalRate": 0.0125,
                "nonTaxable": 0.0,
                "notRegisteredIndicator": false,
                "situs": "DESTINATION",
                "taxCollectedFromParty": "BUYER",
                "taxResult": "TAXABLE",
                "taxStructure": "SINGLE_RATE",
                "taxType": "SALES",
                "taxable": 200.0
            }, {
                "calculatedTax": 1.0,
                "calculationRuleId": {
                    "salesTaxHolidayIndicator": false,
                    "userDefined": false,
                    "value": "v3696"
                },
                "effectiveRate": 0.005,
                "exempt": 0.0,
                "imposition": {
                    "impositionId": "v1j3263",
                    "userDefined": false,
                    "value": "Local Sales and Use Tax"
                },
                "impositionType": {
                    "impositionTypeId": "v1",
                    "userDefined": false,
                    "value": "General Sales and Use Tax"
                },
                "inclusionRuleId": {
                    "salesTaxHolidayIndicator": false,
                    "userDefined": false,
                    "value": "v1288770"
                },
                "isService": false,
                "jurisdiction": {
                    "effectiveDate": "1900-01-01",
                    "expirationDate": "9999-12-31",
                    "jurisdictionId": "3263",
                    "jurisdictionType": "DISTRICT",
                    "value": "TRANSPORTATION AUTHORITY (OCTA)"
                },
                "maxTaxIndicator": false,
                "nominalRate": 0.005,
                "nonTaxable": 0.0,
                "notRegisteredIndicator": false,
                "situs": "DESTINATION",
                "taxCollectedFromParty": "BUYER",
                "taxResult": "TAXABLE",
                "taxStructure": "SINGLE_RATE",
                "taxType": "SALES",
                "taxable": 200.0
            }],
            "totalTax": 15.5,
            "transactionType": "SALE"
        }, {
            "customer": {
                "customerCode": {
                    "classCode": "RESELLER",
                    "isBusinessIndicator": false,
                    "value": "BOO1234"
                },
                "destination": {
                    "city": "hudew",
                    "country": "INDIA",
                    "postalCode": "92615",
                    "streetAddress1": "dwdwe",
                    "taxAreaId": "50591530"
                },
                "isTaxExempt": false,
                "taxRegistrations": []
            },
            "extendedPrice": 37.98,
            "fairMarketValue": 37.98,
            "product": {
                "value": "LGS270"
            },
            "quantity": {
                "unitOfMeasure": "EA",
                "value": 1.0
            },
            "seller": {
                "company": "PROduction",
                "taxRegistrations": []
            },
            "taxIncludedIndicator": false,
            "taxes": [{
                "calculatedTax": 2.28,
                "calculationRuleId": {
                    "salesTaxHolidayIndicator": false,
                    "userDefined": false,
                    "value": "v1262305"
                },
                "effectiveRate": 0.06,
                "exempt": 0.0,
                "imposition": {
                    "impositionId": "v1j2398",
                    "userDefined": false,
                    "value": "Sales and Use Tax"
                },
                "impositionType": {
                    "impositionTypeId": "v1",
                    "userDefined": false,
                    "value": "General Sales and Use Tax"
                },
                "inclusionRuleId": {
                    "salesTaxHolidayIndicator": false,
                    "userDefined": false,
                    "value": "v1280125"
                },
                "isService": false,
                "jurisdiction": {
                    "effectiveDate": "1900-01-01",
                    "expirationDate": "9999-12-31",
                    "jurisdictionId": "2398",
                    "jurisdictionType": "STATE",
                    "value": "India"
                },
                "maxTaxIndicator": false,
                "nominalRate": 0.06,
                "nonTaxable": 0.0,
                "notRegisteredIndicator": false,
                "situs": "DESTINATION",
                "taxCollectedFromParty": "BUYER",
                "taxResult": "TAXABLE",
                "taxStructure": "SINGLE_RATE",
                "taxType": "SALES",
                "taxable": 37.98
            }, {
                "calculatedTax": 0.47,
                "calculationRuleId": {
                    "salesTaxHolidayIndicator": false,
                    "userDefined": false,
                    "value": "v1080547"
                },
                "effectiveRate": 0.0125,
                "exempt": 0.0,
                "imposition": {
                    "impositionId": "v1j3262",
                    "userDefined": false,
                    "value": "Local Sales and Use Tax"
                },
                "impositionType": {
                    "impositionTypeId": "v1",
                    "userDefined": false,
                    "value": "General Sales and Use Tax"
                },
                "inclusionRuleId": {
                    "salesTaxHolidayIndicator": false,
                    "userDefined": false,
                    "value": "v1287055"
                },
                "isService": false,
                "jurisdiction": {
                    "effectiveDate": "1900-01-01",
                    "expirationDate": "9999-12-31",
                    "jurisdictionId": "3262",
                    "jurisdictionType": "COUNTY",
                    "value": "ORANGE"
                },
                "maxTaxIndicator": false,
                "nominalRate": 0.0125,
                "nonTaxable": 0.0,
                "notRegisteredIndicator": false,
                "situs": "DESTINATION",
                "taxCollectedFromParty": "BUYER",
                "taxResult": "TAXABLE",
                "taxStructure": "SINGLE_RATE",
                "taxType": "SALES",
                "taxable": 37.98
            }, {
                "calculatedTax": 0.19,
                "calculationRuleId": {
                    "salesTaxHolidayIndicator": false,
                    "userDefined": false,
                    "value": "v3696"
                },
                "effectiveRate": 0.005,
                "exempt": 0.0,
                "imposition": {
                    "impositionId": "v1j3263",
                    "userDefined": false,
                    "value": "Local Sales and Use Tax"
                },
                "impositionType": {
                    "impositionTypeId": "v1",
                    "userDefined": false,
                    "value": "General Sales and Use Tax"
                },
                "inclusionRuleId": {
                    "salesTaxHolidayIndicator": false,
                    "userDefined": false,
                    "value": "v1288770"
                },
                "isService": false,
                "jurisdiction": {
                    "effectiveDate": "1900-01-01",
                    "expirationDate": "9999-12-31",
                    "jurisdictionId": "3263",
                    "jurisdictionType": "DISTRICT",
                    "value": "TRANSPORTATION AUTHORITY (OCTA)"
                },
                "maxTaxIndicator": false,
                "nominalRate": 0.005,
                "nonTaxable": 0.0,
                "notRegisteredIndicator": false,
                "situs": "DESTINATION",
                "taxCollectedFromParty": "BUYER",
                "taxResult": "TAXABLE",
                "taxStructure": "SINGLE_RATE",
                "taxType": "SALES",
                "taxable": 37.98
            }],
            "totalTax": 2.94,
            "transactionType": "SALE"
        }],
        "postingDate": "2022-11-01",
        "returnAssistedParametersIndicator": true,
        "roundAtLineLevel": false,
        "saleMessageType": "INVOICE",
        "subTotal": 237.98,
        "total": 256.42,
        "totalTax": 18.44,
        "transactionType": "SALE"
    }
}

我试图将这些值插入到html输入中

<input type="text" name="taxt" value="">
<input type="text" name="taxt" value="">
8zzbczxx

8zzbczxx1#

使用index作为DOM元素的索引。
也不需要第一个$.each()lineItems仅在data属性中,因此直接访问它即可。

success:function(data){
    $.each(JSON.parse(data).data.lineItems, function(index, item){
        $("input[name=taxt]").eq(index).val(item.totalTax);
    });
}

相关问题