JavaScript:一个简单的“比较"功能不起作用? [英] JavaScript: a simple 'compare' function not working?

查看:34
本文介绍了JavaScript:一个简单的“比较"功能不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

代码像这样.它是一个函数,它接受两个参数"a"和"b",然后将两个参数进行比较并发出警告.但这对我不起作用!

The code goes like this. It a function which takes in two parameters 'a' and 'b' and compares them both and alerts the output. But this isn't working for me!

<script type="text/javascript">
function compare(a, b) {
if (a < b) {
    alert("A is less than B");
} else if (a > b) {
    alert("A is greater than B");
} else {
    alert("A is equal to B");
}
}

</script>

JsFiddle链接: http://jsfiddle.net/tTCG6/2/

JsFiddle Link :http://jsfiddle.net/tTCG6/2/

有人可以帮我吗?

推荐答案

您正在使用Java无法识别的智能引号(" ).请使用普通引号(" ).

You are using smart quotes (" "), which Javascript will not recognize. Use normal quotes (" ") instead.

使用智能引号可能是因为您使用的是自动执行此操作的文本编辑器.您应该使用纯文本编辑器(例如Windows的记事本或Mac的TextEdit),或使用IDE.

The smart quotes may be because you are using a text editor that does this automatically. You should use a plaintext editor (like Notepad for Windows or TextEdit for a Mac), or use an IDE.

这篇关于JavaScript:一个简单的“比较"功能不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆