日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

js动态创建html控件,通过JS动态添加html控件后,添加样式以及OnClick

發布時間:2025/3/20 51 豆豆
生活随笔 收集整理的這篇文章主要介紹了 js动态创建html控件,通过JS动态添加html控件后,添加样式以及OnClick 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

/**

* 新增標簽

* @param count

*/

function addLabel(count){

var image_id_obj = document.getElementById("image_id_"+count);

var div = document.createElement("div");

div.id="image_id_"+count;

//創建file

var inputText = document.createElement("input");

inputText.type = "file";

inputText.name = "q1lqzp_"+count;

inputText.id = "q1lqzp_"+count;

//創建上傳按鈕

var btn = document.createElement("input");

btn.type = "button";

btn.value = "上傳";

btn.id = "upload_btn_"+count;

btn.onclick = function(){

upload('q1lqzp_'+count,this);

};

//創建取消按鈕

var btn_close = document.createElement("input");

btn_close.type = "button";

btn_close.value = "取消";

btn_close.id = "close_btn_"+count;

btn_close.style.cssText="display: none;";

btn_close.onclick = function(){

};

var img = document.createElement("img");

img.id = "tp_"+count;

//添加css樣式

img.style.cssText="display: none;";

div.appendChild(inputText);

div.appendChild(btn);

div.appendChild(btn_close);

div.appendChild(img);

// div.innerHTML=img;

//往上一個div添加新創建的div

$("#image_id_"+parseInt(parseInt(count)-1)).after(div);

}

總結

以上是生活随笔為你收集整理的js动态创建html控件,通过JS动态添加html控件后,添加样式以及OnClick的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。