Skip to content
You are here: خانه arrow ترفندها arrow HTML Hacks arrow javascript return

javascript return چاپ ايميل
امتياز: / 3
ضعيفعالي 
وقتي كه شما براي رخداد يك المنت از onclick استفاده ميكنيد تنها تعريف ميكنيد كه هنگام كليك روي دكمه كاري را انجام دهد اما انجام فعاليت از پيش تايين شده اي مثل ارسال فرم براي كنترل submit رو كنترل نخواهد كرد :

<input type="submit" name="Submit" value="Submit" onclick="cal();" />

شما دو راه حل خواهيد داشت . يكي اينكه از كنترل button به جاي submit استفاده كنيد :

<input type="button" name="Submit3" value="Button" onclick="cal()"/>
<button type="button" onclick="cal()">Button 2</button>

و راه حل ديگه اينكه هنگام صدا زدن يك تابع از return استفاده كنيد به همراه همون المنت submit.
در صورتي كه تابع يا حاصل كد اجرا شده مقدار true باشد فرم ارسال ميشود اما در صورتي كه false باشد فرم ارسال نخواهد شد :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>return</title>
</head>
<script language="javascript">
function cal()
{
    alert('salam');
    return false;
}
function cal2()
{
    alert('salam');
    return true;
}
</script>
<body>
<form id="form1" name="form1" method="post" action="">
      <input type="text" name="textfield" />
    <input type="submit" name="Submit" value="submit return cal" onclick="return cal();" />
    <input type="submit" name="Submit" value="submit cal" onclick="cal();" />
    <input type="submit" name="Submit2" value="submit return cal2" onclick="return cal2();" />
    <input type="submit" name="Submit2" value="submit cal2" onclick="cal2();" />
    <input type="button" name="Submit3" value="Button" onclick="cal()"/>
    <button type="button" onclick="cal()">Button 2</button>
</form>
</body>
</html>

برگزيدن اين صفحه (66) | نقل قول اين مطلب | بيننده: 2707

ارسال نظر
RSS نظرها

نوشتن نظر
نام:
ايميل:
صفحه اصلي:
عنوان:
BBCode:Web AddressEmail AddressBold TextItalic TextUnderlined TextQuoteCodeOpen ListList ItemClose List
نظر:



كد:* Code
من اين نظر را دوستانه جهت تماس ارسال ميكنم

Powered by AkoComment Tweaked Special Edition v.1.4.6
AkoComment © Copyright 2004 by Arthur Konze - www.mamboportal.com
All right reserved


 
< بعد   قبل >
 

ورود اعضا






رمز عبورتان را فراموش كرده ايد؟
هنوز ثبت نام نكرده ايد? فرم ثبت نام

خبر خوان

كاربران آنلاين در سايت