我正在使用id
后面的jquery选择器$("#rs_0.01").val();
所以我的小问题是:这个有效与否? 因为它不适用于我的情况。
答案 0 :(得分:2)
检查documentation of jQuery Selectors
使用任何元字符(例如!“#$%&'()* +,。/:;< =>?@ [] ^`{|}〜)作为文字作为名称的一部分,必须使用两个反斜杠进行转义:\。例如,id =“foo.bar”的元素可以使用选择器$(“#foo \ .bar”)。W3C CSS规范包含有关有效CSS选择器的完整规则集。还有一个有用的是Mathias Bynens关于标识符的CSS字符转义序列的博客条目。
<小时/> 所以你可以使用
$("#rs_0\\.01").val();
或使用attribute equals selector代替
$("[id='rs_0.01']").val();
答案 1 :(得分:0)
使用: 你需要逃避特殊的角色:
$("#rs_0\\.01").val();
答案 2 :(得分:0)
在你的情况下,你有几种方法可以通过使用你在问题中指定的同名的id选择器来检索文本框的值。
一种方法是这样做:
{
"apiVersion": "v1",
"swaggerVersion": "1.2",
"basePath": "http://localhost:3000",
"resourcePath": "trucks",
"apis": [
{
"path": "/api/v1/trucks.json",
"operations": [
{
"summary": "Fetches all Trucks",
"parameters": [
{
"paramType": "header",
"name": "X-Auth-Token",
"type": "string",
"description": "Authentication Token",
"required": true
}
],
"responseMessages": [
{
"code": 401,
"responseModel": null,
"message": "Unauthorized"
},
{
"code": 406,
"responseModel": null,
"message": "The request you made is not acceptable"
}
],
"nickname": "API::V1::Trucks#index",
"method": "get"
}
]
}
],
"authorizations": null
}
或者您可以在选择器名称之间使用转义序列,如下所示:
$("[id='rs_0.01']").val();