不管上层用什么复杂的,我觉得.net里面既然jquery已经成为自带,那还是有必要了解jquery 的,哪怕最基础的一套
关于下拉框,首先是访问问题,看到这种#ID subProperty的方式 然后 .each(),然后function(){}语法看起来挺自然的
jQuery: Dynamically updating a drop down list事实上这个不是个煎蛋的事情
$('#DropDownList1 option').each(function() { var option = this; });
add CSS selectors to the options that we wanted to hide. That worked fine in Chrome and Firefox but Internet Explorer seems to ignore CSS selectors inside a drop down list so none of the options were being hidden.看起来可以实现的方法很多,但汪汪考虑到多个浏览器之后,解决方法就很少了。
<select id="foo" name="foo"> <option value="A" selected="selected">A</option> <option value="B">B</option> <option value="C">C</option> <option value="Not applicable">Not applicable</option> </select>
var originalFooOptions = $("#foo > option");用这个方法》获得当前所有选项,是个数组//
文本框 var dependentfiled=$("#fildedFooIsedit");
dependentField
foo.empty(); $(originalFooOptions).each(function() { var newOption = $(this).clone(); if ($(this).val() === dependentField.val()) { newOption.attr("selected", "selected"); } newOption.appendTo(foo); });//string trim() jquery采用一下方式调用
becomes:
<script type="text/javascript"> $(document).ready(function () { var data = { 'Country': 'India', 'Country1': 'USA', 'Country2': 'UK',
'Country3': 'Rusia', 'Country4': 'France' }; var s = $('<select />');-------选择到 下拉况,这是创建。。 。。 for (var val in data) {
$('<option />', { value: val, text: data[val] }).appendTo(s); } s.appendTo('body'); }); </script>
===
The problem was due to controls which were copy/pasted and did not have unique ID's
===selector
JQuery: var ddlCollection = $("select[name$='ddlDynamicDropDown']")
ListItem[] items = new ListItem[3];
items[0] = new ListItem("One", "1");
items[1] = new ListItem("Two", "2");
items[2] = new ListItem("Three", "3");
DropDownList1.Items.AddRange(items);
DropDownList1.DataBind();
public class SomeController { private Dictionary<string, Func<UserData,ActionResult>> handleAction = new Dictionary<string, Func<UserData,ActionResult>> { { "Back", SaveAction }, { "Next", NextAction }, { "Save", SaveAction } }; public ActionResult TheAction(string whichButton, UserData userData) { if(handleAction.ContainsKey(whichButton)) { return handleAction[whichButton](userData); } throw Exception(""); } private ActionResult NextAction(UserData userData) { // do cool stuff } }