Hướng dẫn dùng x-5/-2 JavaScript
Comparison and Logical operators có thể hiểu nôm na là so sánh và biểu thức điều kiện, chúng được sử dụng để kiểm tra một điều kiện nào đó đúng hay sai. Show Nội dung chính Show
Nội dung chính
Nội dung chính
Bài viết này được đăng tại freetuts.net, không được copy dưới mọi hình thức. Các toán tử so sánh được sử dụng trong các câu lệnh logic để xác định xem giá trị của biến này có bằng, lớn hơn, nhỏ hơn .vv. giá trị của biến kia hay không. Toán tửMô TảVí dụKết quảDEMO==so sánh bằng giá trịx = 5, x == 8 x = 5, x == 5 Bài viết này được đăng tại [free tuts .net] x = 5, x == "5" False True True DEMO DEMO DEMO ===so sánh bằng giá trị và kiểu dữ liệux = 5, x === 5 x = 5, x === "5" True False DEMO DEMO !==so sánh khác giá trịx = 5, x != 10 TrueDEMO!==so sánh khác giá trị hoặc khác kiểu dữ liệux = 5, x !== 5 x = 5, x !== "5" x = 5, x !== 10 False True True DEMO DEMO DEMO Cách sử dụngCác toán tử so sánh đươc sử dụng trong các biểu thức điều kiện để kiểm tra giá trị sau đó thực hiện một hành động nào đó tùy thuộc vào kết quả trả về của phép so sánh: Ví dụ if (score < 50) result = "Bad"; if (score > 50) result = "Good";Logical OperatorsCác toán tử logic được sử dụng kết hợp với các phép so sánh để xác định tính logic giữa các biến hoặc các giá trị. Toán tửMô tảVí dụKết quảDEMO&so sánh vàx = 5, y = 4, ( x > 4 & y > 3)TrueDEMO||so sánh hoặcx = 5, y = 4, ( x > 4 || y > 6)TrueDEMO!phủ định của phép so sánhx = 5, y = 4, !( x == y)TrueDEMOConditional (Ternary) OperatorConditional Operator có thể hiểu là một biểu thức điều kiện, javascript sử dụng nó để gán giá trị cho biến, giá trị sẽ thay đổi tùy thuộc vào kết quả trả về của điều kiện. Cú pháp: variablename = (condition) ? value1:value2 var skill = (score > 50) ? "good":"bad"; Trong ví dụ trên, nếu điểm bạn nhập vào nhỏ hơn 50 hoặc bằng 50, 'your skill is bad" sẽ được in ra, ngược lại, nếu score cao hơn 50, "your skill is good" sẽ được in ra. Comparing Different TypesCác phép so sánh đối với các kiểu dữ liệu khác nhau có thể trả về những kết quả không theo ý muốn. Khi so sánh một chuỗi với một số, chuỗi sẽ được chuyển thành kiểu số và tiến hành so sánh. Một chuỗi rỗng sẽ được chuyển thành 0, một chuỗi không thể chuyển thành kiểu số sẽ được chuyển thành NaN, các phép so sánh với NaN sẽ luôn trả về False. Ví dụKết quảDEMO10 < 99TrueDEMO10 < "99"TrueDEMO10 > "ten"FalseDEMO10 < "ten"FalseDEMO10 == "ten"FalseDEMO"10" < "2"TrueDEMO"10" > "2"FalseDEMO"10" == "2"FalseDEMOKhi so sánh hai chuỗi, "2" sẽ lớn hơn "10" vì 2 lớn hơn 1 theo bảng chữ cái. Để có kết quả chính xác, các biến nên được chuyển thành kiểu Number trước khi so sánh. Get started by including Bootstrap’s production-ready CSS and JavaScript via CDN without the need for any build steps. See it in practice with this Bootstrap CodePen demo.
As reference, here are our primary CDN links. DescriptionURLCSS 0You can also use the CDN to fetch any of our additional builds listed in the Contents page. Next stepsJS componentsCurious which components explicitly require our JavaScript and Popper? Click the show components link below. If you’re at all unsure about the general page structure, keep reading for an example page template. Show components requiring JavaScript
Important globalsBootstrap employs a handful of important global styles and settings, all of which are almost exclusively geared towards the normalization of cross browser styles. Let’s dive in. HTML5 doctypeBootstrap requires the use of the HTML5 doctype. Without it, you’ll see some funky and incomplete styling.
Bootstrap is developed mobile first, a strategy in which we optimize code for mobile devices first and then scale up components as necessary using CSS media queries. To ensure proper rendering and touch zooming for all devices, add the responsive viewport meta tag to your .
You can see an example of this in action in the quick start. Box-sizingFor more straightforward sizing in CSS, we switch the global 1 value from 2 to 3. This ensures 4 does not affect the final computed width of an element, but it can cause problems with some third-party software like Google Maps and Google Custom Search Engine.On the rare occasion you need to override it, use something like the following:
With the above snippet, nested elements—including generated content via 5 and 6—will all inherit the specified 1 for that 8.Learn more about box model and sizing at CSS Tricks. RebootFor improved cross-browser rendering, we use Reboot to correct inconsistencies across browsers and devices while providing slightly more opinionated resets to common HTML elements. Stay up-to-date on the development of Bootstrap and reach out to the community with these helpful resources. |