javascript
1 const wrwpper = document.querySelector("#wrapper"), 2 playground = document.querySelector("#playground"), 3 operator = document.querySelector("#operator"), 4 discription = document.querySelector("#discription"), 5 WIDTH = playground.clientHeight, 6 HEIGHT = playground.clientWidth; 7 playground.addEventListener("click",start); 8 9 const htmltag = ["article","selection","nav","aside","h"+"hnumber","header","footer","address"]; 10 const cssstyle = ["width","font","text-align","line-height","color","background","margin","padding","border"] 11 12 13 function Showsomething(wrapper_id,usearray,event,clickevent){ 14 var wrapper = Setdom("div",operator,wrapper_id); 15 flagment = document.createDocumentFragment(); 16 for(let i=0;i<usearray.length;i++){ 17 let button = document.createElement("button"); 18 button.textContent = usearray[i]; 19 button.style.width = WIDTH*0.2 + "px"; 20 button.style.height = HEIGHT*0.1 + "px"; 21 button.addEventListener(event,clickevent); 22 flagment.appendChild(button); 23 } 24 wrapper.appendChild(flagment); 25 } 26 27 function Showhtml(){ 28 Showsomething("htmlwrapper",htmltag,"click",Sethtml); 29 } 30 31 function Counttag(tag){ 32 return count = playground.getElementsByTagName(tag).length; 33 } 34 35 function Sethtml(){ 36 tag = this.textContent; 37 count = Counttag(tag); 38 nowelement = Setdom(tag,playground,tag + "_" +count,"defined_style"); 39 console.log(nowelement); 40 Showcss(); 41 } 42 43 function Setdom(element_tag, parentHTML, element_id, element_class) { 44 var element = document.createElement(element_tag); 45 parentHTML.appendChild(element); 46 element.setAttribute("id", element_id); 47 if (element_class) { 48 element.classList.add(element_class); 49 } 50 return element; 51 } 52 53 function test(){ 54 alert("Showcss"); 55 } 56 57 function Showcss(){ 58document.querySelector("#htmlwrapper").parentNode.removeChild(document.querySelector("#htmlwrapper")); 59 Showsomething("csswrapper",cssstyle,"click",test); 60 const unitselect = '<form id="cssunit_wrapper"><input type="radio" name="cssvalue_unit" value="px">px<input type="radio" name="cssvalue_unit" value="vw">vh<input type="radio" name="cssvalue_unit" value="vh">vh<input type="radio" name="cssvalue_unit" value="%">%</form>'; 61 const value = '<input id="cssvalue" type="text" maxlength="8"></input>'; 62 document.querySelector("#csswrapper").innerHTML += unitselect+value; 63 }
javascriptでhtml.cssを構築できるようなものを作っています。
その中でhtmlのタグを選んだ後にcssのプロパティを選べるようにしたいです。
しかし、2回目にイベントを与えることになる
Showsomething("csswrapper",cssstyle,"click",test);
ここでイベントが加わっていないようです。
解決方法を教えてください。。。
html
1<div id="wrapper"> 2<div id="playground"> 3</div> 4<div id="operator"> 5</div>
質問が途中で切れているように見受けられます。
質問は編集できますので落ち着いて編集し、投稿前にプレビュー確認してください