andreyshowa
دوشنبه 05 تیر 1391, 09:14 صبح
سلام.میخوام یک فرم رو با استفاده از jquery اعتبارسنجی کنم.این کد نمونه ای کوچک از فرمه:
<head>
<script type="text/javascript" src="jquery1.js">
</script>
$('document').ready(function(){
$('p').css('color','blue');
$('#submit').click(function()
{
$("p").addClass('required');
<script type="text/javascript>
</script>
<style type="text/css>
.required{color:white;background:red}
.error{color:red;font-size:10px;display:none;}
</style>
</head>
<body>
<form name="f1" id="f1" method="post" >
<label>نام</label><br/>
<input name="name" id="name" type="text" /><br/>
<label>پست الکترونيک</label><br/>
<input name="email" id="email" type="text" /><br/>
<input name="submit" id="submit" type="submit" /><br/>
<p>hi</p>
</form>
</body>
ولی وقتی سابمیت میزنم فقط یک لحظه تغییرات قسمت jquery دیده میشه ولی بلافاصله به حالت اول برمیگرده.اشکال کار کجاست؟
البته این کد خلاصه شده وفقط برای تست نتیجه س.
</div>
<head>
<script type="text/javascript" src="jquery1.js">
</script>
$('document').ready(function(){
$('p').css('color','blue');
$('#submit').click(function()
{
$("p").addClass('required');
<script type="text/javascript>
</script>
<style type="text/css>
.required{color:white;background:red}
.error{color:red;font-size:10px;display:none;}
</style>
</head>
<body>
<form name="f1" id="f1" method="post" >
<label>نام</label><br/>
<input name="name" id="name" type="text" /><br/>
<label>پست الکترونيک</label><br/>
<input name="email" id="email" type="text" /><br/>
<input name="submit" id="submit" type="submit" /><br/>
<p>hi</p>
</form>
</body>
ولی وقتی سابمیت میزنم فقط یک لحظه تغییرات قسمت jquery دیده میشه ولی بلافاصله به حالت اول برمیگرده.اشکال کار کجاست؟
البته این کد خلاصه شده وفقط برای تست نتیجه س.
</div>