动态更改行背景不起作用

问题描述 投票:0回答:1
ractivejs
1个回答
0
投票

我找到了解决您问题的方法:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<script src='https://cdn.jsdelivr.net/npm/ractive'></script>
</head>
<body>
<div id="target" class="container"></div>
<script id="template" type='text/ractive'>
<table>
{{#each physicianList}}
<tr onclick="testFunction({{.testNumber}})" style="background-color: {{.testNumber == testNumberSelected ? '#cce5ff' : 'inherit'}}">
<td>{{.testNumber}}</td>                    
</tr>
{{/each}}
</table>
</script>

<script>
            
var ractive = new Ractive({
            el: '#target',
            template: '#template',
            data: {
                physicianList: [{testNumber: 0},{testNumber: 0},{testNumber:1}],
                testNumberSelected: 0
            },
        });   
        function testFunction(testNumber) {
                ractive.set('testNumberSelected', testNumber);
            } 
</script>
</body>
</html>
© www.soinside.com 2019 - 2024. All rights reserved.