简单解释一下bool函数,是不是return ture就继续执行,returnphp curl bool falsee 就不执

js return true-学网-提供健康,养生,留学,移民,创业,汽车等信息
js return true
则return不代表函数的结束.还要再加一个break. 一般我们使用return false和return true来表示一些特殊的情况.如:脚本永不出错是window.onerror=function(){} 禁止选中... 不能不加!它的作用在于当验证返回false时,即输入不合法时,阻止表单提交。如果不加,当输入不合法时,是会弹出警告信息,但接着网页就会继续进入处理表单的页面,这时验证就...布尔值 true 表示真 ,false 表示假 return true是返回真值,用来判断后执行条件运算的 比如 判断 函数返回值为真 时 可以提交表单,函数返回值为假时 取消提交表单你这个return 没有用 去掉吧不管你有几个return,程序会执行到遇见第一个 return的时候跳出,如果你执行到了if里面,那就在return false时跳出,不会执行到return true。反之就执行到return true 而不会执行retur...JS大小写敏感。 True自然是认不得,true才对。 &a onclick='return &%=ViewState[&AUTHOR&].ToString()==Session[&userName&].ToString()?&true...return 意思为返回,在程序中同样如此。 比如 function Test1(obj){ var resultObj=obj //可对传入参数进行处理。 return resultO } 在这个列子中:obj 代表的是一...返回一个Boolean对象(是Boolean.TRUE或者Boolean.FALSE)。 public static Boolean valueOf(boolean b) { return (b ? TRUE : FALSE); } 之间差别在于new Boolean开辟了...form&这个html对象的一个方法名,其值(一字符串)就是其方法体,默认返回 和Jav... Return False 就相当于终止符,Return True 就相当于执行符。 在js中return false的作用一...&&);& & & && & & & ... ;} &&& &&&var&jieguo=&return&nbsp...
您可能还关注:&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
大类导航: |今天看啥 热点:
今天做一个表单提交验证的工作,做到其中一段时,我想提交表单时,先验证是否填写了姓名,如果没填写,右侧显示出提示信息,并取消提交,如果已填写,则正常提交。
初步想法,想自己写个 js 函数,在提交按钮处用 onclick 事件,判断填写了则用js提交表单,没填写则蹦出提示信息,但基本上实现了半天,达不到我想要的结果,最后才发现原来有 onsubmit 这个属性,它写在 form 标签里。
onclick 和 onsubmit 的区别:
onSubmit 是表单上(也只能是表单)用的,提交表单前会触发。
onClick 是按钮等控件上用的,用来触发点击事件。
用作数据验证的时候,可以选择在 submit 按钮上的 onclick 中验证,可以在 onsubmit 中验证。但是从事件触发顺序上来说,onclick更早。顺序是:
用户点击按钮 -> onclick -> 如果onclick返回有效或未处理 onclick 则提交表单 -> onsubmit -> 如果 onsubmit 未处理或返回true,则提交,否则取消提交。
onsubmit 中返回 false 会引起取消表单提交,onclick 中返回 false 则会引起此次点击操作被判断为无效,则也就不会引起表单提交。
&a href="somewhere.html" onClick="doSomething()">
在上面的例子中,doSomething()会首先执行,然后浏览器会打开链接(默认动作)。
事件处理程序可以返回一个布尔值(ture或者false),false的含义就是“不要进行默认动作”。
&a href="somewhere.html" onClick="doSomething(); return false">
这个链接就不会跟着执行了。这个函数执行之后程序返回false,告诉浏览器不要执行默认动作。
有时候有必要让函数决定什么时候该执行什么时候不该执行默认动作。所以我们可以把例子改成:
&a href="somewhere.html" onClick="return doSomething()">
function doSomething()
return confirm('Do you really want to follow this link?')
这就是(非常简单的)用户交互。用户会被问一个问题,如果回答是肯定的那么函数返回 true,如果取消了那么久返回一个 false。这个返回值会被事件处理程序捕获,然后转给事件本身。如果是 flase 那么默认动作就不会被执行——链接不会进入。
然而,不是所有的默认动作都能被阻止。比如 unload 事件就不行。假设用户关闭浏览器窗口——触发了 unload 事件。如果你能阻止关闭窗口,那么窗口会违背用户的意愿而一直打开着么? 用微软的 beforeunload 属性来阻止 unload。
返回 false 来阻止默认动作是所有浏览器都支持的这是事件处理程序的基本组成。如今的事件处理程序模型还添加了一些新的方法来阻止默认动作:
W3C 给事件添加了 preventDefalut() 方法。如果你引用了这个方法那么默认动作就会被阻止。
微软给事件添加了 returnValue 属性。如果你设置他的值为 false 那么默认动作也会被阻止。
但是用不着这些个,简单的返回 false 就够了。
相关搜索:
相关阅读:
相关频道:
&&&&&&&&&&&&&&&&&&
HTML5最近更新java 使用return终止代码继续运行 - 黄彪学习笔记 - ITeye技术网站
博客分类:
import org.junit.T
public class ReturnNullTest {
* @param args
public static void main(String[] args) {
new ReturnNullTest().stop();
if (false) {
// 前面没有return 语句,则会继续执行下面打印语句
System.out.println("after stop");
public void test1() {
new ReturnNullTest().stop();
if (true) {
// 最后一条语句不会继续执行
System.out.println("after stop");
public void test2() {
new ReturnNullTest().stop();
// 下面如果直接return 则编译器会直接报错
System.out.println("after stop");
public void stop() {
if (true) {
System.out.println("first");
System.out.println("second");
public String returnStop() {
if (true) {
System.out.println("returnStop first");
return "huangbiao";
System.out.println("returnStop second");
public void test3() {
String result = new ReturnNullTest().returnStop();
System.out.println(result);
// 下面如果直接return 则编译器会直接报错
System.out.println("after stop");
浏览: 1741121 次
来自: 长沙
下载439次,就没一个说谢谢。ps:谢谢博主的分享。
很好,很实用
请教您一个问题:这个ganymed-ssh2-build210 ...& 检测变量是否是布尔型
PHP is_bool 检测变量是否是布尔型
检测变量是否是布尔型
bool is_bool
Example #1 is_bool() 示例
&?php$a&=&false;$b&=&0;//&因为&$a&是布尔型,所以结果为真if&(is_bool($a))&{&&&&print&"Yes,&this&is&a&boolean";}//&因为&$b&不是布尔型,所以结果为非真if&(is_bool($b))&{&&&&print&"Yes,&this&is&a&boolean";}?&
PHP is_bool note #1
If you want to convert a string representation of a boolean ,like "yes", "on", "true", "false",etc..., to an actual boolean, you can try this:
$myString = "On";
$b = filter_var($myString, FILTER_VALIDATE_BOOLEAN);
This will return TRUE for "1", "true", "on" and "yes". Returns FALSE otherwise.
PHP is_bool note #2
Seems this is a most wanted function, so here is my version of it. I have been using this one for several years no and it works perfect for my needs. I have added "sloppy" human logic to it, and you could easily extend to your flavour. Like in norway some would use "ja" and "nei" instead of "yes" and "no".
function _bool($var){
& if(is_bool($var)){
&&& return $var;
& } else if($var === NULL || $var === 'NULL' || $var === 'null'){
&&& return false;
& } else if(is_string($var)){
&&& $var = trim($var);
&&& if($var=='false'){ return false;
&&& } else if($var=='true'){ return true;
&&& } else if($var=='no'){ return false;
&&& } else if($var=='yes'){ return true;
&&& } else if($var=='off'){ return false;
&&& } else if($var=='on'){ return true;
&&& } else if($var==''){ return false;
&&& } else if(ctype_digit($var)){
&& && if((int) $var)
&& & && return true;
&& & && else
&& & && return false;
&&& } else { return true; }
& } else if(ctype_digit((string) $var)){
&& && if((int) $var)
&& & && return true;
&& & && else
&& & && return false;
& } else if(is_array($var)){
&&& if(count($var))
&& && return true;
&& && else
&& && return false;
& } else if(is_object($var)){
&&& return true;} else {
&&& return true;}
PHP is_bool note #3
Here is the function which I use when pasring boolean variables from config files
function boolVal($var) {
&&& switch ($var) {
&& & && case $var == true:
&& & && case $var == 1:
&& & && case strtolower($var) == 'true':
&& & && case strtolower($var) == 'on':
&& & && case strtolower($var) == 'yes':
&& & && case strtolower($var) == 'y':
&& & & & && $out = 1;
&& & & & &&
&& & && default: $out = 0;
&&& return $out;
I am woundering why php does not have a function to do this
Motaz Abuthiab
PHP is_bool note #4
Just another little function which doesn't exist yet, but I find mighty useful, especially when working with AJAX and APIs.
function boolval($in, $strict=false) {
&&& $out = null;
&&& if (in_array($in,array('false', 'False', 'FALSE', 'no', 'No', 'n', 'N', '0', 'off',
&& & & & & & & & & & & & & 'Off', 'OFF', false, 0, null), true)) {
&& & && $out = false;
&&& } else if ($strict) {
&& & && if (in_array($in,array('true', 'True', 'TRUE', 'yes', 'Yes', 'y', 'Y', '1',
&& & & & & & & & & & & & & & & 'on', 'On', 'ON', true, 1), true)) {
&& & & & && $out = true;
&&& } else {
&& & && $out = ($in?true:false);
&&& return $out;
It may be pretty inefficient, but it does the job.
PHP is_bool note #5
@ emmanuel del grande
You don't need to break when you return...
function bool($var) {
&&& switch (strtolower($var)) {
&& & && case ("true"):
&& & && case ("false"):
&& & && default: die("whatever you want it to tell");
PHP is_bool note #6
@ emanueledelgrande at email dot it
(bool) or (boolean) is allowed for type casting a variable. No function like intval, etc but the functionality exists.
PHP is_bool note #7
I think there's a hole in the PHP typecasting methods:
you have the (int) function, the (float) function and the (string) function, but no function to force a string variable into the boolean type.
It's obvious that forcing unconditionally the type of variables into arrays and objects is inappropriate, but boolean type is the most basic one for each programming language, that's why I guessed that a (bool) function already existed.
Moreover, with the increasing trend of RSS data streaming, the parsing of an XML string into an object often requires to typecast as boolean values the content of XML tags, normally returned as string by the object method get_content().
I wrote the following function, which also uses a "native PHP style" error message:
function bool($var) {
&&& switch (strtolower($var)) {
&& & && case ("true"):
&& & & & && return true;
&& & & & &&
&& & && case ("false"):
&& & & & && return false;
&& & & & &&
&& & && default:
&& & & & && die("&br /&
&b&Warning:&/b& Invalid argument supplied for ".__FUNCTION__." function in &b&".__FILE__."&/b& on line &b&".__LINE__."&/b&: the argument can contain only 'true' or 'false' values as a string.&br /&
Here it is a small example:
$xmlResponse = "&?xml version="1.0" encoding="utf-8"?&";
$xmlResponse .= "&Result&";
$xmlResponse .= "&AuthError&false&/AuthError&";
$xmlResponse .= "&TransferStatus&true&/TransferStatus&";
$xmlResponse .= "&/Result&";
if (! $responseDoc = domxml_open_mem($xmlResponse, DOMXML_LOAD_PARSING, $XmlParsingError)) {
&&& echo "Error while parsing the XML string:&br /&".print_r($XmlParsingError, TRUE);
&&& $ResultNode = $responseDoc-&get_elements_by_tagname('Result');
&&& $AuthError = $ResultNode[0]-&get_elements_by_tagname('AuthError');
&&& $auth_error = bool($AuthError[0]-&get_content());
&&& $TransferStatus = $ResultNode[0]-&get_elements_by_tagname('TransferStatus');
&&& $transfer_status = bool($TransferStatus[0]-&get_content());
&&& if (! $auth_error) { echo "Auth OK&br /&"; } else { echo "Auth error&br /&"; }
&&& if ($transfer_status) { echo "Transfer OK&br /&"; } else { echo "Transfer error&br /&"; }
It would be useful this function to be implemented in the core of PHP5.
PHP is_bool note #8
Small caveat to rh's post: back in PHP 3, "0" would be considered non-empty (i.e., empty would return false), even though (bool) on "0" would al thus, they would not be complete opposites for someone using PHP 3.
PHP is_bool note #9
pu what he means to say is that empty($x) is the opposite of (bool)$x.& is_bool($x) returns true where $x === false.
PHPVariable handling - 函数}

我要回帖

更多关于 ture false 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信