2012-03-31 69 views
0

考慮下面的代碼如何查看函數值?

<input type="button" value="Submit" onclick="checkform(form); someotherfunction();" 

其中checkform返回真或假,在一個形式中使用的功能。

我該如何檢查checkform()的值是否爲false,然後取消輸入,以免它調用someotherfunction(),如果它真的反之亦然。

我曾嘗試

<input type="button" value="Submit" onclick="return checkform(form); someotherfunction();" 

其中這麼想的通話someotherfunction(),因爲在所有它的返回無論值,我怎麼能檢查是否checkform()是真實的,因此它可以再調用someotherfunction()

我不想檢查在someothefunction()裏面的checkform()的值,是否可以檢查<input這一行?

回答

1

if

onclick="if(checkform(form)){someotherfunction();}" 
+2

你也可以做'onclick ='checkform(form)&& someotherfunction();「' – 2012-03-31 04:20:59

+0

你和你的花哨短路...... /賤民 – canon 2012-03-31 04:29:42

+2

戴伊拿着我們的if語句! – 2012-03-31 04:31:37

0

這將幫助你

<script> 
var formExist = true; 

function someotherfunction(){ 
    if(formExist){ 
     // do your stuff... 
    } 
} 
</script> 

<body> 
... 

<input type="button" value="Submit" onclick="formExist = checkform(form); someotherfunction();" /> 

... 
</body> 

如果這是不行的完美不是使用相同的機制,但調用checkform someotherfunction()(), definetely工作...