Ajax in Spring MVC achieves level two linkage

Source: Internet
Author: User

Write a project today encountered a two-level linkage, during the encounter points, write a blog record.

Background controller:

@RequestMapping ("/faulttype")
@ResponseBody
Public map<string,object> faulttype (int id,httpservletrequest request) throws IOException
{
String returnmessage = "";
Get all child class failure types
List<faulttype> Faulist=faulttypeservice.getbyid (ID);
if (Faulist.size () >0) {
Request.setattribute ("Childtype", faulist);
ReturnMessage = "OK";
}else {
ReturnMessage = "no information found";
}


//*************************************************************
map<string,object> Returnmap = new hashmap<string,object> ();
Returnmap.put ("Childtype", faulist);
return returnmap;
}

————————————————————————————————————————————————————————————

Front-desk JSP:

<div class= "Col-sm-3" >
<div class= "Form-group" >
<label class= "col-3 control-label no-padding-right" >
Fault type: </label>
<select name= "Faulttype" id= "Faulttype" onchange= "Javascript:typechange ()" >
<c:foreach items= "${faultlist}" var= "Faulist" >
<option value= "${faulist.faultid}" >${faulist.faultcontent}</option>
</c:forEach>
</select>

</div>
</div>
<div class= "Col-sm-3" >
<div class= "Form-group" >
<label class= "col-3 control-label no-padding-right" >
Fault: </label>
<input id= "Childtypecont" name= "Childtypecont"
Value= "" type= "hidden" class= "col-sm-4 Form-control" placeholder= "Fault" >

<select name= "Faulttype1" id= "Faulttype1" ">
<option>--Please select--</option>
<c:foreach items= "${childtype}" var= "Faulist" >
<option value= "${faulist.faultid}" >${faulist.faultcontent}</option>
</c:forEach>
</select>
</select>
</div>
</div>

Js:

function Typechange () {
var type=$ ("#faulttype"). Val ();

var html = "<option>--Please select--</option>";
var commiturl = "faulttype.do?id=" + type;

$.ajax ({
Type: "POST",
ContentType: "Application/json",
Url:commiturl,
DataType: ' JSON ',
Success:function (Result) {
var curedata = $.extend (true, [], result);
if (curedata.childtype! = null) {
for (Var i=0;i<curedata.childtype.length;i++) {

html+= "<option value= '" +curedata.childtype[i].faultid+ ">" +curedata.childtype[i].faultcontent+ "</ Option> ";
}
$ ("#faulttype1"). empty ();
$ (HTML). AppendTo ("#faulttype1");

} }
});
}


——————————————————————————————————————————————————————————————————————————

The following is written by someone else (original address: http://blog.csdn.net/gis__/article/details/6647464)

——————————————————————————————————————————————————————————————————————————

A bad memory can be collected:

1, drop-down box:

var cc1 = $ (". formcselect[@name=' country '] option[@selected]"). text ();//Get a drop-down menu of selected items (note that there are spaces in the middle)

var cc2 = $ ('. formcselect[@name="Country"]). Val (); Get the value of the selected item in the drop-down menu

var cc3 = $ ('. FORMC select[@name="country"] '). attr ("id");//The ID property value of the selected item that gets the drop-down menu

$ ("#select"). empty ();//Empty the drop-down box//$ ("#select"). HTML (");

$ ("<optionvalueoptionvalue=' 1 '>1111</option>"). AppendTo ("#select") option to add a drop-down box

A little explanation:

1.select[@name=' country '] option[@selected] means having the Name property,

and the option element with the selected attribute in the Select element with the attribute value of ' country ';

You can see that there is an @ at the beginning of the property is followed by.

2, Radio Box:

$ ("input[@type=radio][@checked]"). Val (); Get the value of the selected item in the Radio box (note that there are no spaces in the middle)

$ ("input[@type=radio][@value=2]"). attr ("Checked", ' checked ');//Set Radio box value=2 is selected. ( Note There are no spaces in the middle)

3, check box:

$ ("input[@type=checkbox][@checked]"). Val ();//Gets the value of the check box for the first item selected

$ ("input[@type=checkbox][@checked]"). each (function () {////Because the check box is generally selected as multiple, you can loop the output

Alert (This). Val ());

});

$ ("#chk1"). attr ("Checked", "");//Not ticked

$ ("#chk2"). attr ("Checked", true);//tick

if ($ ("#chk1"). attr (' checked ') ==undefined) {}//Determine if a tick has been made

Of course the jquery selector is powerful. There are many other ways.

<script src= "jquery-1.2.1.js"type= "Text/javascript"></script>

<script language= "javascript"type= "Text/javascript">

$ (document). Ready (function () {

$ ("#selectTest"). Change (function ()

{

Alert ("Hello");

Alert ($ ("#selectTest"). attr ("name"));

$ ("a"). attr ("href", "xx.html");

window.location.href="xx.html";

Alert ($ ("#selectTest"). Val ());

Alert ($ ("#selectTest option[@selected]"). text ());

$ ("#selectTest"). attr ("Value", "2");

});

});

</Script>

<ahrefahref="#">aaass</a>

<!-- drop-down box--

  1. <select id= "selecttest"name= "Selecttest">
  2. <optionvalueoptionvalue="1">11</option>
  3. <optionvalueoptionvalue="2">22</option>
  4. <optionvalueoptionvalue="3">33</option>
  5. <optionvalueoptionvalue="4">44</option>
  6. <optionvalueoptionvalue="5">55</option>
  7. <optionvalueoptionvalue="6">66</option>
  8. </Select>
  9. Jqueryradio value, checkbox value, select Value, Radio selected, CheckBox selected, select selected, and its related gets the value of a set of radio selected items
  10. var item = $ (' input[@name=items][@checked] '). Val ();
  11. Gets the text of the Select selected item
  12. var item = $ ("select[@name=items] option[@selected]"). Text ();
  13. The second element of the Select drop-down box is the currently selected value
  14. $ (' #select_id ') [0]. SelectedIndex = 1;
  15. Radio the second element of a radio group is the currently selected value
  16. $ (' input[@name=items] '). Get (1). checked = true;
  17. Get Value:
  18. text box, text area: $ ("#txt"). attr ("value");
  19. Multi Box checkbox:$ ("#checkbox_id"). attr ("value");
  20. Radio Group Radio: $ ("input[@type=radio][@checked]"). Val ();
  21. Drop-down box select: $ (' #sel '). Val ();
  22. Control form elements:
  23. text box, text area: $ ("#txt"). attr ("Value", "");//Clear Contents
  24. $ ("#txt"). attr ("value", ' 11 ');//fill content
  25. Multiple marquee checkbox: $ ("#chk1"). attr ("Checked", "");//No Tick
  26. $ ("#chk2"). attr ("Checked", true);//tick
  27. if ($ ("#chk1"). attr (' checked ') ==undefined)//Determine if a tick has been made
  28. Radio Group radio:$ ("input[@type=Radio]"). attr ("Checked", ' 2 ');//Set value=2 for the currently selected Item
  29. drop-down box select:$ ("#sel"). attr ("value", '-sel3 ');//Set the VALUE=-SEL3 item as the current selection
  30. $ ("<optionvalueoptionvalue=' 1 '>1111</option>< OptionValueoptionvalue=' 2 '>2222</option> "). AppendTo (" #sel ")// option to add a drop-down box
  31. $ ("#sel"). empty ();//Empty drop-down box
  32. Gets the value of a set of radio selected items
  33. var item = $ (' input[@name=items][@checked] '). Val ();
  34. Gets the text of the Select selected item
  35. var item = $ ("select[@name=items] option[@selected]"). Text ();
  36. The second element of the Select drop-down box is the currently selected value
  37. $ (' #select_id ') [0]. SelectedIndex = 1;
  38. Radio the second element of a radio group is the currently selected value
  39. $ (' input[@name=items] '). Get (1). checked = true;
  40. Get Value:
  41. text box, text area: $ ("#txt"). attr ("value");
  42. Multi Box checkbox:$ ("#checkbox_id"). attr ("value");
  43. Radio Group Radio: $ ("input[@type=radio][@checked]"). Val ();
  44. Drop-down box select: $ (' #sel '). Val ();
  45. Control form elements:
  46. text box, text area: $ ("#txt"). attr ("Value", "");//Clear Contents
  47. $ ("#txt"). attr ("value", ' 11 ');//fill content
  48. Multiple marquee checkbox: $ ("#chk1"). attr ("Checked", "");//No Tick
  49. $ ("#chk2"). attr ("Checked", true);//tick
  50. if ($ ("#chk1"). attr (' checked ') ==undefined)//Determine if a tick has been made
  51. Radio Group radio:$ ("input[@type=Radio]"). attr ("Checked", ' 2 ');//Set value=2 for the currently selected Item
  52. drop-down box select:$ ("#sel"). attr ("value", '-sel3 ');//Set the VALUE=-SEL3 item as the current selection
  53. $ ("<optionvalueoptionvalue=' 1 '>1111</option>< OptionValueoptionvalue=' 2 '>2222</option> "). AppendTo (" #sel ")// option to add a drop-down box
  54. $ ("#sel"). empty ();//Empty drop-down box

Ajax in Spring MVC achieves level two linkage

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.