脚本函数参数如何判断数值?例如function (data) {} 我想在这函数里面判断data数值。如果为空就alert("不能为空");否则执行其他代码。。如何写? 请给个例子来 谢谢
------解决方案--------------------------------------------------------
什么时候判断,什么时候调用
------解决方案--------------------------------------------------------
- HTML code
<html><head><script type="text/javascript"> function test(data) { if(!data){alert('参数不能为空');} else{alert('参数='+data);} }</script></head><body> <input type="button" value="abc" onclick="test('abc')" /> <input type="button" value="null" onclick="test(null)" /></body></html>
------解决方案--------------------------------------------------------
success: function (data) {
var ID = '';
//我要在这里判断data值!!
$(data).find("Table").each(function() {
中的参数Data应该是你请求页面的返回值吧,你可以输出下Data看下它的值是什么,请求页面是否成功将值返回回来了,确定有正确的返回值了再进行判断吧。还有建议换个参数名字,提高可读性