誰かが私に手伝ってもらえますか? 私は食料品のリストについては、単純なHTMLコードを持っている:jQueryで既存のjQueryボタンのボタンを追加
<!DOCTYPE html>
<html>
<head>
<title>Let's buy...</title>
<link rel="stylesheet" href="css/normalize.css">
<link rel="stylesheet" href="css/main.css">
</head>
<body>
<h2 class="title">My grocery list<span id="counter"></span> </h2>
<ul id="list-items"></ul>
<div id="newItemButton"><button href="#" id="showForm">new item</button></div>
<form id="newItemForm">
<input type="text" id="itemDescription" placeholder="Add item..."/>
<input type="submit" id="addButton" value="add" />
</form>
<script
src="https://code.jquery.com/jquery-3.2.1.min.js"
integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
crossorigin="anonymous"></script>
<!-- <script type="text/javascript"
src="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script> -->
<script type="text/javascript" src="js/javascript.js"></script>
</body>
</html>
をそして私は、ユーザーがリストに要素を追加しています - ユーザーが項目を追加する場合、その項目はボタンが付いています。今度は、そのボタンに "append()"を加えた4つのボタンを追加するボタンを "アイテムを変更"し、ユーザの好みに応じて、赤、緑、オレンジ、グレーのようなアイテムの色を変更するためにクリックします。 私はそれらのボタンを追加しようとしていますが、私はそれを追加していないようです、それはページに表示されません - ちょうど言って - 私はただ一つのボタンを追加しようとしました:)。
$(function() {
let $list, $newItemForm, $newItemButton;
let item = '';
$list = $('ul');
$newItemForm = $('#newItemForm');
$newItemButton = $('#newItemButton');
function updateCount() {
let items = $('li').length;
$('#counter').text(items);
}
updateCount();
$newItemButton.show();
$newItemForm.hide();
$('#showForm').on('click', function() {
$newItemButton.hide();
$newItemForm.show();
});
$newItemForm.on('submit', function(e) {
e.preventDefault();
let text = $('input:text').val();
$list.append('<li>' + text + '<button id="btn-change">change item</button><hr></li>');
$('input:text').val('');
updateCount();
});
、これは= 'プロセスを追加するボタン' です: ...ここに私のjQueryコードである
$('#btn-change').one('click', function() {
let b = $('<input/>').attr({
type: "button",
id: "hot",
value: 'hot'
});
$("button").append(b);
});