PDA

View Full Version : سوال: checkbox و غیر فعال کردن دکمه در جدول



mahdioo12194
جمعه 29 شهریور 1392, 13:33 عصر
سلام فرض کنید یه جدول داریم که دو ستون داره و چندین سطر در ستون اول چک باکس قرار دارد و در ستون دوم

دکمه حالا می خوام با زدن تیک چک باکس دکمه در همان سطر مورد نظر غیر فعال یا فعال شود؟!!!

jalil_gh
جمعه 29 شهریور 1392, 14:16 عصر
<table>
<tbody>
<tr>
<td><input type="checkbox"></td>
<td><button>button</button></td>
</tr>
<tr>
<td><input type="checkbox"></td>
<td><button>button</button></td>
</tr>
<tr>
<td><input type="checkbox"></td>
<td><button>button</button></td>
</tr>
</tbody>
</table>
<script src='lib/jquery.js'></script>
<script>

$('table').on('click', 'input[type="checkbox"]', function() {
var $this = $(this);
if ($this.prop('checked')) {
$this.parents('tr').find('button').prop('disabled' , true);
} else {
$this.parents('tr').find('button').prop('disabled' , false);
}
});

mahdioo12194
جمعه 29 شهریور 1392, 16:18 عصر
<table>
<tbody>
<tr>
<td><input type="checkbox"></td>
<td><button>button</button></td>
</tr>
<tr>
<td><input type="checkbox"></td>
<td><button>button</button></td>
</tr>
<tr>
<td><input type="checkbox"></td>
<td><button>button</button></td>
</tr>
</tbody>
</table>
<script src='lib/jquery.js'></script>
<script>

$('table').on('click', 'input[type="checkbox"]', function() {
var $this = $(this);
if ($this.prop('checked')) {
$this.parents('tr').find('button').prop('disabled' , true);
} else {
$this.parents('tr').find('button').prop('disabled' , false);
}
});


کار نمی کنه!!؟؟

sinoser
جمعه 29 شهریور 1392, 16:58 عصر
دوستمون با نسخه های قدمی نوشته اینم ورژن جدیدش بالای 1.4

$(':input').on('click', function() {
var $this = $(this);
if ($this.is(':checked')) {
$this.parents('tr').find('button').attr('disabled' , true);
} else {
$this.parents('tr').find('button').attr('disabled' , false);
}
});

mahdioo12194
جمعه 29 شهریور 1392, 17:17 عصر
دوستمون با نسخه های قدمی نوشته اینم ورژن جدیدش بالای 1.4

$(':input').on('click', function() {
var $this = $(this);
if ($this.is(':checked')) {
$this.parents('tr').find('button').attr('disabled' , true);
} else {
$this.parents('tr').find('button').attr('disabled' , false);
}
});


اینم کار نمی کنه که!!!

jalil_gh
جمعه 29 شهریور 1392, 17:23 عصر
من امتحان کردم که کار میکرد. error چی میده؟

mahdioo12194
جمعه 29 شهریور 1392, 17:26 عصر
من امتحان کردم که کار میکرد. error چی میده؟

ارور نمیده اما وقتی تیک میزنم دکمه غیر فعال نمیشه!! از jquery-1.8.2.js هم استفاده می کنم!!

mahdioo12194
جمعه 29 شهریور 1392, 17:28 عصر
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>

<script src="jquery-1.8.2.js" type="text/javascript"></script>

<script type="text/javascript">

$(':input').on('click', function () {
var $this = $(this);
if ($this.is(':checked')) {
$this.parents('tr').find('button').attr('disabled' , true);
} else {
$this.parents('tr').find('button').attr('disabled' , false);
}
});

</script>



</head>
<body>
<form id="form1" runat="server">
<div>

<table>
<tbody>
<tr>
<td><input type="checkbox"/></td>
<td><button>button</button></td>
</tr>
<tr>
<td><input type="checkbox"/></td>
<td><button>button</button></td>
</tr>
<tr>
<td><input type="checkbox"/></td>
<td><button>button</button></td>
</tr>
</tbody>
</table>




</div>
</form>
</body>
</html>

mahdioo12194
جمعه 29 شهریور 1392, 17:35 عصر
در ضمن حالا اگه مشکل قبلی برطرف شد یه کار دیگه می خوام بکنم که دو تا چک باکس بزارم و اگر هر دو اونها تیک خورد اون دکمه فعال بشه و گرنه فعال نشه!!!

jalil_gh
جمعه 29 شهریور 1392, 19:47 عصر
کدهاتو داخل document.ready بزار. اینجوری
$(document).ready(function() {
// your code here
});

// or

$(function() {
// your code here
});

mahdioo12194
جمعه 29 شهریور 1392, 19:57 عصر
در ضمن حالا اگه مشکل قبلی برطرف شد یه کار دیگه می خوام بکنم که دو تا چک باکس بزارم و اگر هر دو اونها تیک خورد اون دکمه فعال بشه و گرنه فعال نشه!!!

ممنون فقط اینم جواب میدی؟!!

jalil_gh
جمعه 29 شهریور 1392, 19:58 عصر
منظورت اینجوریه؟؟

<table>
<tbody>
<tr>
<td><input type="checkbox"><input type="checkbox"></td>
<td><button>button</button></td>
</tr>
<tr>
<td><input type="checkbox"><input type="checkbox"></td>
<td><button>button</button></td>
</tr>
<tr>
<td><input type="checkbox"><input type="checkbox"></td>
<td><button>button</button></td>
</tr>
</tbody>
</table>
<script src='lib/jquery.js'></script>
<script>

$('table').on('click', 'input[type="checkbox"]', function() {
var $this = $(this),
allChecked = true;

$this.parents('tr').find('input[type="checkbox"]').each(function(index, item) {
if (!$(item).prop('checked')) {
allChecked = false;
};
});

if (allChecked) {
$this.parents('tr').find('button').prop('disabled' , true);
} else {
$this.parents('tr').find('button').prop('disabled' , false);
}
});

</script>