削除アイコンが押されると、ブートストラップリストから要素を削除します。 add関数は、文字列と削除アイコンをリストに追加します。私はリストを反復して、削除ボタンがクリックされたかどうかをチェックし、クリックされた場合は削除することを確認します。問題は、オブジェクトulの要素にどのようにアクセスするのか分からないことです。削除ボタンに機能を追加する
var ul = document.getElementById("list");
function isBlank(str) {
return (!str || /^\s*$/.test(str));
}
function add()
{
if(!isBlank(document.getElementById("task").value)) {
var onClick=document.createElement('div');
onClick.clasName="onclick";
var iCon = document.createElement('div');
var li = document.createElement("il");
var closeSpan = document.createElement("span");
iCon.className = "glyphicon glyphicon-remove";
onClick.appendChild(iCon);
closeSpan.setAttribute("class", "badge");
closeSpan.appendChild(onClick);
li.innerHTML = document.getElementById('task').value;
li.setAttribute("class", "list-group-item");
li.appendChild(closeSpan);
ul.appendChild(li);
}
}
function remove()
{
for(var i=0; i<ul.maxlength();i++)
{
if(ul[i].child().child().onclick==true)
{
alert("click x");
}
}
}
remove();
</script>
function add()
{
if(!isBlank(document.getElementById("task").value)) {
var iCon = document.createElement('div');
var li = document.createElement("il");
var closeSpan = document.createElement("span");
iCon.className = "glyphicon glyphicon-remove";
iCon.addEventListener("onclick",remove());
closeSpan.setAttribute("class", "badge");
closeSpan.appendChild(iCon);
li.innerHTML = document.getElementById('task').value;
li.setAttribute("class", "list-group-item");
li.appendChild(closeSpan);
ul.appendChild(li);
}
}
function remove(argument)
{
ul.removeChild(ul.argument);
}
存在フィドルメイト – Siddharth
結局、私はそれを行うだろうが、私はそれは私たちがマークアップで何申し訳ありません – TheMathNoob
を必要としない、学習段階で午前? – Geeky