我正在尝试使用jQuery方法.attr()来更改id的字体大小,如下所示:
import 'dart:async' show Future;
import 'dart:convert';
import 'package:flutter/services.dart' show rootBundle;
import 'package:flutter/material.dart';
import 'model.dart';
Future<String> _loadCategoryfromAssets() async {
return await rootBundle.loadString('assets/data/list.json');
}
Future loadCategory() async {
await wait(1);
String jsonString = await _loadCategoryfromAssets();
final jsonResponse = json.decode(jsonString);
Category category = Category.fromJson(jsonResponse);
print(category.categorylist[0].categoryTitle);
print(category.categorylist[0].categoryPost[0].postTitle);
}
Future wait(int seconds) {
return new Future.delayed(Duration(seconds: seconds), () => {});
}
class Doa extends StatefulWidget {
Doa({Key key}) : super(key: key);
_DoaState createState() => _DoaState();
}
class _DoaState extends State<Doa> {
Widget futureWidget() {
return new FutureBuilder(
future: loadCategory(),
builder: (context, snapshot) {
if (snapshot.hasData) {
return new Container(
child: Row(
children: <Widget>[
ListView.builder(
itemBuilder: (BuildContext context, index) {
return Column(
children: <Widget>[
InkWell(
onTap: () {},
child: Text(
snapshot.data.category.categorylist[index].categoryTitle,
),
)
],
);
}
)
],
),
);
}
},
);
}
@override
Widget build(BuildContext context) {
return SafeArea(
top: false,
bottom: false,
child: Scaffold(
body: futureWidget(),
));
}
}
哪个不起作用。
此ID当前正在这样安装在我的外部CSS中:
$("#level-title").attr("font-size", "1rem");
如何使用jQuery适当更改其字体大小?
我的完整样式表可以在这里查看:
https://github.com/raschmitt/simon-game/blob/master/styles.css#L17
还有我的Js文件在这里:
https://github.com/raschmitt/simon-game/blob/master/game.js#L48
答案 0 :(得分:3)
使用.css()
$("#level-title").css("font-size", "1rem");
答案 1 :(得分:3)
要使用jQuery管理元素的样式,您必须使用.css()
$("#level-title").css("font-size", "1rem");
尽管不是首选,但您仍然可以通过设置 style 属性来使用attr()
:
$("#level-title").attr("style", "font-size: 1rem");