How 1.html introduction of css and js files
css: <link rel = "stylesheet" href = "css / index1.css (this is the address of my file)">
script: <script type = "text / javascript" src = "js / jquery-3.4.1.min.js (this is the address of my folder)"> </ script>
2.jquery common operations
Setting and returns HTML () method of the selected content element (inner HTML).
js
<script> $(document).ready(function(){ $("#btn1").click(function(){ $("p").html("Hello world"); }); }); </script>
findindex and tostring used in combination to find in the current item is an array of items:
table_list = [1,1,2,35,5,9] $(document).ready(function(){ itemNum = table_list.findIndex(function(item){ return item.toString() = myItem.toString() }); });
Val () method returns the set value or the selected element
$(document).ready(function(){ $("#btn1").click(function(){ $(":text").val("hello world"); }); });
Get value exists inside the select data items selected
<select class="mySelect"> <option value="switch" data-name="开关">开关</option> <option value="light" data-name="灯光">灯光</option> </select>
$ ( "mySelect.") find ( "option: selected") attr ( "data-name"); data- obtaining the selected item.. name value of "switch"; $
( ".mySelect") Val (). ; get the value of the switch value.
parselnt XX is converted to the number: Number () for all types, parseInt () and parseFloat () applied to the string
Analyzing myitem indexOf itemArray exists in the array, there is a return to the first index, -1 otherwise:
indexOf () method is to look for the positive sequence, lastIndexOf () is a flashback to find // https://www.cnblogs.com/clear93/p/7928218.html
var index = JSON.stringify(itemArray).indexOf(JSON.stringify(myitem));
append html and values inserted into the document required
$("#btn").click(function(){ html = '<tr>' + '<td>' + '<img src="./images/item.png" alt="">' + '</td>' + '<td>' + '<span>品牌: </span>' + '<span>' + $(".myValue").val() + '</span>' + '</td>' + '</tr>'; $("list").append(html); });
location.reload () to refresh the page
window.location.reload
attr () and removeAttr ()
$ ( "input.") attr ( "placeholder", " Please enter your password").
$ ( "the INPUT") removeAttr ( "DATE-targer").;
prop() 和 removeprop()
<script> </scrip$("#btn").prop("checked"); //truet> <label> <input type="checkbox" value="复选框" id="btn" checked = "true" disabled = ""> </label>
Depth understanding
<script> $(document).ready(function(){ $("btn").click(function(){ $("p").removeAttr("style"); }); }); </script>