好的,新开发,我在id和tekst中有正确的值,但页面没有正确重定向,只是刷新,没有错误。代码:
<!DOCTYPE html>
<html lang="nl">
<head>
<meta charset="UTF-8">
<title>my page</title>
<link href="https://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Shadows+Into+Light+Two" rel="stylesheet">
<link rel="stylesheet" href="css/todo.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
</head><body>
<p>Hallo <a href="profile.php?user=Christophe">Christophe</a>!</p>
<nav class="nav">
<ul>
<li><a href="#" id="dnperm">Notificaties toestaan</a></li>
<li><a href="update.php">Details wijzigen</a></li>
<li><a href="changepassword.php">Wachtwoord wijzigen</a></li>
<li><a href="logout.php">Afmelden</a></li>
</ul>
</nav>
<script>
var dnperm = document.getElementById('dnperm');
dnperm.addEventListener('click', function(e) {
e.preventDefault();
if(!window.Notification) {
alert('Sorry, notificaties worden niet ondersteund.');
} else {
Notification.requestPermission(function(p) {
console.log(p);
});
}
});
</script>
<script src="includes/jquery-3.1.1.min.js" type="text/javascript"></script>
<link href="css/f_clone_Notify.css" rel="stylesheet" />
<script>
var tekst;
$(document).ready(function() {
var id;
$('input[id="id"]').change( function(e) {
if($(this).is(':checked')){
window.location = "mark.php?as=done&item=" + $(this).val();
}
else
{
window.location = "mark.php?as=notdone&item=" + $(this).val();
}
});
$('.item').on('DOMSubtreeModified',function(){
tekst = $(this).text();
});
//$('#id').attr('value');
//id = $('#id').attr('value');
//console.log('click');
//url = "mark.php?as=edit&item=" + id + "&tekst=" + tekst;
//$( '#wijzigen' ).attr("href", url);
});
function wijzigen(id) {
url = "mark.php?as=edit&item=" + id + "&tekst=" + tekst;
$( '#wijzigen' ).attr("href", url);
}
</script>
<div class="list">
<h1 class="header">C1pa To Do</h1>
<ul class="items">
<li>
<input type="checkbox" id="id" value="1" />
<span id="item" contenteditable="true" class="item">edit text</span>
<a href="" class="hidden">
<script>
var notify;
window.setInterval(function() {
if(Notification.permission === "default") {
console.log("Notificaties niet toegestaan");
} else {
notify = new Notification("Nieuw bericht van C1pa To Do", {
body: "edit text",
icon: "images/notification.ico",
tag:"1"
});
notify.onclick = function() {
window.location = "mark.php?as=done&item=" + this.tag;
}
}
}, 60000);
</script> </a>
<a href="" onclick="wijzigen(1)" id="wijzigen" value="1" class="done-button">wijzigen</a>
<!--<a href="mark.php?as=notdone&item=" class="done-button">Niet gedaan</a>-->
</li>
<li>
<input type="checkbox" id="id" value="2" />
<span id="item" contenteditable="true" class="item">do something else db</span>
<a href="" class="hidden">
<script>
var notify;
window.setInterval(function() {
if(Notification.permission === "default") {
console.log("Notificaties niet toegestaan");
} else {
notify = new Notification("Nieuw bericht van C1pa To Do", {
body: "do something else db",
icon: "images/notification.ico",
tag:"2"
});
notify.onclick = function() {
window.location = "mark.php?as=done&item=" + this.tag;
}
}
}, 60000);
</script> </a>
<a href="" onclick="wijzigen(2)" id="wijzigen" value="2" class="done-button">wijzigen</a>
<!--<a href="mark.php?as=notdone&item=" class="done-button">Niet gedaan</a>-->
</li>
<li>
<input type="checkbox" id="id" value="11" />
<span id="item" contenteditable="true" class="item">something new</span>
<a href="" class="hidden">
</a>
<a href="" onclick="wijzigen(11)" id="wijzigen" value="11" class="done-button">wijzigen</a>
<!--<a href="mark.php?as=notdone&item=" class="done-button">Niet gedaan</a>-->
</li>
</ul>
<form class="item-add" action="add.php" method="post">
<input type="text" name="name" placeholder="Hier iets typen" class="input" autocomplete="off" required>
<input type="submit" class="submit" value="Toevoegen">
</form>
</body>
</html>
希望我现在把代码正确放在这里,这样你就可以运行它(参见注释)
答案 0 :(得分:0)
为什么在您已经知道的时候需要获取ID。
我认为你正试图获得Id的价值。 如果是这样,你可以使用 id = $(&#39;#id&#39;)。val(); 而不是id = $(&#39;#id&#39;)。attr(&#39; value&#39;);