jquery createlement创建多个 [英] jquery createlement create more then one

查看:59
本文介绍了jquery createlement创建多个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的aspx页面中有这个

i have this in my aspx page

<div id="dialog">
		<div id="textresultfree"></div>
        <div id="myDivResult"></div>
</div>
<button id="creatItem" onclick="createItem();return false;">Boka tid</button>





这是我的功能,





Here is my function,

$(function () {
     var para = document.createElement("p");
     var element = document.getElementById("textresultfree");
     element.appendChild(para);
     var node = document.createTextNode("Lediga tider att boka");
     para.appendChild(node);



     var myDiv = document.getElementById("myDivResult");
     var selectList = document.createElement("select");
     myDiv.appendChild(selectList);

     $("#dialog").dialog({
         autoOpen: false

     });
     $("#creatItem").on("click", function() {
         $("#dialog").dialog("open");



         var free = "";
         for (var j = 0; j < bookedFreeTimes.length; j++) {

             free = bookedFreeTimes[j];
             var array = new Array(free);

             for (var k = 0; k < array.length; k++) {

                 var option = document.createElement("option");
                 option.text = array[k];
                 selectList.appendChild(option);

             }
         }

     }

     );
 });





每次点击我的按钮,它会创建超过1个节点为什么?它第一次点击按钮第一次不工作?





更新

== =

我想在这里创建onclick。





Everytime i click on my button its creates more then 1 node why? and it wont work first time i click on the button only second time?


UPDATE
===
I want to create onclick inside here.

<button onclick="createItem();return false;">Boka tid</button>




       <div id="dialog">
       <div id="textresultfree"></div>
       <div id="myDivResult"></div>

   </div>





就像我在这里onclick =createItem(); return false;


此函数也调用onclick,但我已经在我的aspx页面创建了onclick,



那么如何我现在应该通过我的aspx页面与onclick交谈。





Like i have here onclick="createItem();return false;"

This function also calls onclick, but i have already created onclick in my aspx page,

So how should this code now that i am talking to onclick from my aspx page.

 var para = document.createElement("p");
    para.id = "para";
    var node = document.createTextNode("Lediga tider att boka");
    para.appendChild(node);
    var element = document.getElementById("textresultfree");
    element.appendChild(para);

    var myDiv = document.getElementById("myDivResult");
    var selectList = document.createElement("select");
    myDiv.appendChild(selectList);
  
   

    $(function () {$("#dialog").dialog({
            autoOpen: false

    });


        $("#creatItem").on("click", function() {
            $("#dialog").dialog("open");

            

            var free = "";
            for (var j = 0; j < bookedFreeTimes.length; j++) {

                free = bookedFreeTimes[j];
                var array = new Array(free);

                for (var k = 0; k < array.length; k++) {
                    
                    var option = document.createElement("option");
                    option.text = array[k];
                    selectList.appendChild(option);

                }
            }
                return false;
            }

        );
    });


}





在这条线上





On this line

$("#creatItem").on("click", function() {





因为这与



Because that is the same as

onclick="createItem();return false;"





所以我怎么说我想用这个



So how to i say i want to work with this

onclick="createItem();return false;"





我的函数内部



Inside my function

推荐答案

function (){
var para = document .createElement( p);
var element = document .getElementById( textresultfree );
element.appendChild(para);
var node = document .createTextNode( Lediga tider att boka);
para.appendChild(node);



var myDiv = document .getElementById ( myDivResult);
var selectList = document .createElement( 选择);
myDiv.appendChild(selectList);
(function () { var para = document.createElement("p"); var element = document.getElementById("textresultfree"); element.appendChild(para); var node = document.createTextNode("Lediga tider att boka"); para.appendChild(node); var myDiv = document.getElementById("myDivResult"); var selectList = document.createElement("select"); myDiv.appendChild(selectList);


#dialog )。对话框({
autoOpen: false

});
("#dialog").dialog({ autoOpen: false });


#creatItem)。on( 点击 function (){
("#creatItem").on("click", function() {


这篇关于jquery createlement创建多个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆