When writing js scripts, some spelling functions are often used, such as calling setTimeout
var msgalert="test";
function TestAlert(msg)
{
alert(msg)
}
$(document).ready( function () {
$("#btnCancel").click(function (e) {
setTimeout("TestAlert(" msgalert ")",1000);
});
})
After checking for a long time, why the dialog box does not pop up. After checking for a long time, I discovered that a pair of single quotes
$(document).ready(function () {
$("#btnCancel").click(function (e) {
setTimeout("TestAlert('" msgalert "')",1000 ; 🎜>
Copy code
The code is as follows:
);
}
function TestAlert(msg)
{
alert(msg)
}
$(document).ready(function () {
$("#btnCancel").click(function (e) {
dalayAlert(msgalert,1000)
}) ;
})
Due to the use of closures, it is much simpler and it is easy to check for errors.