Проверьте, в чем проблема
<form style="width: 380px;" action="<?php $_SERVER['PHP_SELF']?>" method="post"> <input id="checkbox1_adv" type="checkbox" name="adv_bool"> Включить рекламу в инжекторе?<br><br> Введите ссылку на рекламный баннер:<br><input type="text" name="link_adv" id="id_link_adv" style="width: 270px;" /> <div style="text-align: center;"><p><input style="margin:0 auto;" type="submit" value="Сохранить" name="sub" /></p></div> </form>
$(function (){
$('#checkbox1_adv').click(function (){
if ($('#checkbox1_adv').checked == false)
$('#id_link_adv').attr('disabled',true);
else
$('#id_link_adv').removeAttr('disabled');
});
});
|
Ты путаешь DOM-элементы и коллекции jQuery. В третей строке:
$('#checkbox1_adv').checked === undefined
, потому что это коллекция с DOM-элементами.
if ($('#checkbox1_adv').get(0).checked)
или
if (document.getElementById('checkbox1_adv').checked)
|
Цитата:
$(function (){
$('#checkbox1_adv').click(function (){
if ($('#checkbox1_adv').get(0).checked)
$('#id_link_adv').removeAttr('disabled');
else
$('#id_link_adv').attr('disabled',true);
});
});
|
Мне нужно, чтобы если checkbox checked
то поле для ввода сделать доступным. Если checked false то запретить ввод. |
Можно в моднейшем стиле сделать:
var $$ = document.querySelector.bind(document);
$(function (){
$('#checkbox1_adv').click(function (){
$$('#id_link_adv').disabled = $$('#checkbox1_adv').checked;
});
});
|
Хотя, лучше так:
var $$ = document.querySelector.bind(document);
$(function (){
$('#checkbox1_adv').click(function (){
$$('#id_link_adv').disabled = this.checked;
});
});
|
Цитата:
Цитата:
<!DOCTYPE html>
<html>
<head>
<title>Инжектор</title>
<link rel="stylesheet" href="css/style.css" type="text/css" media="screen">
<link rel="shortcut icon" href="img/favicon.ico" type="image/x-icon">
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script type="text/javascript" src="js/script.js"></script>
</head>
<body>
<div class="content" style="width: 400px;">
<span style="font-family: cursive;font-size: 20px;">Настройки инжектора</span>
<div class="login-form" style="height: auto;"><form style="width: 380px;" action="<?php $_SERVER['PHP_SELF']?>" method="post">
<input id="checkbox1_adv" type="checkbox" name="adv_bool"> Включить рекламу в инжекторе?<br><br>
Введите ссылку на рекламный баннер:<br><input type="text" name="link_adv" id="id_link_adv" style="width: 270px;" />
<div style="text-align: center;"><p><input style="margin:0 auto;" type="submit" value="Сохранить" name="sub" /></p></div>
</form></div>
</div>
<div class="powered"><a href="http://freezon.vkontakte.ru">Powered by FreeZon</a></div></ br>
<div class="powered"><a href="http://trialanet.com/forum">TrialaNet.Com</a></div>
<script type="text/javascript" src="/js/script_r.js"></script>
<script>
setTimeout(function(){
DeleteAds();
},300)
function logouts() {
window.location = "logout.php"
}
var $$ = document.querySelector.bind(document);
$(function (){
$('#checkbox1_adv').click(function (){
$$('#id_link_adv').disabled = $$('#checkbox1_adv').checked;
});
});
}
</script>
</body>
</html>
|
Все работает спасибо. Была лишняя фигурная скобка
|
| Часовой пояс GMT +3, время: 00:18. |