访问 jQuery 返回值
Accessing jQuery returned value
我正在尝试访问返回值并添加 .contains
检查,这样我就可以知道是否需要重新加载页面。我一直在尝试执行以下操作:
alert(msg.d);
if(msg.d.contains("deleted"))
location.reload();
返回的对象是一个字符串。
它确实向我显示了警告消息,但不会在必要时重新加载页面。我是不是做错了什么?
没有.contians()
方法,您需要使用String.prototype.indexOf()
The indexOf()
method returns the index within the calling String object of the first occurrence of the specified value, starting the search at fromIndex. Returns -1 if the value is not found.
代码
if(msg.d.indexOf("deleted") > -1)
location.reload();
使用JavaScript的hasOwnProperty
函数,像这样:
if(msg.d.hasOwnProperty("deleted") {
location.reload();
}
您可以尝试这样的操作:
if( /deleted/.test(msg.d) ) {
location.reload();
}
我正在尝试访问返回值并添加 .contains
检查,这样我就可以知道是否需要重新加载页面。我一直在尝试执行以下操作:
alert(msg.d);
if(msg.d.contains("deleted"))
location.reload();
返回的对象是一个字符串。
它确实向我显示了警告消息,但不会在必要时重新加载页面。我是不是做错了什么?
没有.contians()
方法,您需要使用String.prototype.indexOf()
The
indexOf()
method returns the index within the calling String object of the first occurrence of the specified value, starting the search at fromIndex. Returns -1 if the value is not found.
代码
if(msg.d.indexOf("deleted") > -1)
location.reload();
使用JavaScript的hasOwnProperty
函数,像这样:
if(msg.d.hasOwnProperty("deleted") {
location.reload();
}
您可以尝试这样的操作:
if( /deleted/.test(msg.d) ) {
location.reload();
}