gpt4 book ai didi

javascript - 如何让 jQuery 选择带有 . (句号)在他们的身份证?

转载 作者:IT老高 更新时间:2023-10-28 13:16:18 30 4
gpt4 key购买 nike

给定以下类和 Controller 操作方法:

public School
{
public Int32 ID { get; set; }
publig String Name { get; set; }
public Address Address { get; set; }
}

public class Address
{
public string Street1 { get; set; }
public string City { get; set; }
public String ZipCode { get; set; }
public String State { get; set; }
public String Country { get; set; }
}

[Authorize(Roles = "SchoolEditor")]
[AcceptVerbs(HttpVerbs.Post)]
public SchoolResponse Edit(Int32 id, FormCollection form)
{
School school = GetSchoolFromRepository(id);

UpdateModel(school, form);

return new SchoolResponse() { School = school };
}

还有如下形式:

<form method="post">
School: <%= Html.TextBox("Name") %><br />
Street: <%= Html.TextBox("Address.Street") %><br />
City: <%= Html.TextBox("Address.City") %><br />
Zip Code: <%= Html.TextBox("Address.ZipCode") %><br />
Sate: <select id="Address.State"></select><br />
Country: <select id="Address.Country"></select><br />
</form>

我可以同时更新 School 实例和学校的 Address 成员。这是相当不错的!感谢 ASP.NET MVC 团队!

但是,我如何使用 jQuery 来选择下拉列表以便我可以预先填充它?我意识到我可以在服务器端执行此操作,但页面上还会有其他动态元素会影响列表。

以下是我目前所拥有的,它不起作用,因为选择器似乎与 ID 不匹配:

$(function() {
$.getJSON("/Location/GetCountryList", null, function(data) {
$("#Address.Country").fillSelect(data);
});
$("#Address.Country").change(function() {
$.getJSON("/Location/GetRegionsForCountry", { country: $(this).val() }, function(data) {
$("#Address.State").fillSelect(data);
});
});
});

最佳答案

来自 Google Groups :

Use two backslashes before each special character.

A backslash in a jQuery selector escapes the next character. But you need two of them because backslash is also the escape character for JavaScript strings. The first backslash escapes the second one, giving you one actual backslash in your string - which then escapes the next character for jQuery.

所以,我猜你在看

$(function() {
$.getJSON("/Location/GetCountryList", null, function(data) {
$("#Address\\.Country").fillSelect(data);
});
$("#Address\\.Country").change(function() {
$.getJSON("/Location/GetRegionsForCountry", { country: $(this).val() }, function(data) {
$("#Address\\.State").fillSelect(data);
});
});
});

还可以查看 How do I select an element by an ID that has characters used in CSS notation?在 jQuery 常见问题解答中。

关于javascript - 如何让 jQuery 选择带有 . (句号)在他们的身份证?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/350292/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com