Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery如何向dom添加元素_Jquery_Dom - Fatal编程技术网

Jquery如何向dom添加元素

Jquery如何向dom添加元素,jquery,dom,Jquery,Dom,您好,我有一个函数可以将combobox添加到页面中,我需要使用这些combobox的值。当我尝试访问jquery代码时,它不起作用。 我想我需要将元素添加到dom中,但我不知道怎么做。 combo的id为“selectCombo”您有几种选择: .prepend() .append() .insertAfter() .insertBefore() 尝试以下方法: $("<div/>", { // PROPERTIES HERE text: "Click me",

您好,我有一个函数可以将combobox添加到页面中,我需要使用这些combobox的值。当我尝试访问jquery代码时,它不起作用。 我想我需要将元素添加到dom中,但我不知道怎么做。
combo的id为“selectCombo”

您有几种选择:

  • .prepend()
  • .append()
  • .insertAfter()
  • .insertBefore()
尝试以下方法:

 $("<div/>", {

  // PROPERTIES HERE

  text: "Click me",

  id: "example",

  "class": "myDiv",      // ('class' is still better in quotes)

  css: {           
     color: "red",
     fontSize: "3em",
     cursor: "pointer"
  },

  on: {
    mouseenter: function() {
      console.log("PLEASE... "+ $(this).text());
    },
    click: function() {
      console.log("Hy! My ID is: "+ this.id);
    }
  },

  append: "<i>!!</i>",

  appendTo: "body"      // Finally, append to any selector

}); 
$(“”{
//这里的财产
文字:“点击我”,
id:“示例”,
“类”:“myDiv”,//(“类”在引号中更好)
css:{
颜色:“红色”,
字体大小:“3em”,
光标:“指针”
},
关于:{
mouseenter:function(){
log(“请…”+$(this.text());
},
单击:函数(){
log(“Hy!我的ID是:+this.ID”);
}
},
附加:“!!”,
appendTo:“body”//最后,附加到任何选择器
}); 

向我们展示您到目前为止在代码方面所做的工作…可能重复的
。add
不会添加到DOM中。true!“将元素添加到匹配的元素集中。”--jquery文档。删除它,谢谢。