search

Home  >  Q&A  >  body text

javascript - How to use the value of create in JS

p.innerHTML = '<label style="font-size: 1.8rem;margin: 1rem 2rem 0 4.8rem;display: inline-block;">评分:</label>'+
                                             '<p style="display: inline-block;" >'+'<p class="icons mui-inline" style="margin-left: 0.6rem;">'+
                                             '<i data-index="1" class="mui-icon mui-icon-star"></i>'+'<i data-index="2" class="mui-icon mui-icon-star"></i>'+
                                             '<i data-index="3" class="mui-icon mui-icon-star"></i>'+'<i data-index="4" class="mui-icon mui-icon-star"></i>'+
                                             '<i data-index="5" class="mui-icon mui-icon-star"></i>'+'</p>'+'</p>'+'</br>'+
                                             '<label style="font-size: 1.8rem;margin: 1rem 2rem 0 4.8rem;">评价:</label>'+
                                             '<textarea style="width: 96%;margin-left: 0.7rem;" ></textarea>'+
                                             '<button id="submit" class="mui-btn mui-btn-block mui-btn-primary">提交</button>';
                                             list1.appendChild(p);`请输入代码`
                                             
    

 submitButton.addEventListener('tap',function(event){
                    if(submitId == id){
                        var submitUrl = baseServerUrl+"/m/biz/issue/addAppraise?issueId="+that.issueId+"&userId="+that.userId+"&level="+that.level+"&appraiseContent="+that.message;
                        $.ajax({
                            type:"get",
                            url:submitUrl,
                            async:true,
                            success:function(data){
                                mui.toast("您已提交");
                            }
                        });
                    }else{
                        mui.toast("您不是问题提出者不能评价");
                    }
                }) 

 我在JS里面crete了一个Button,并且给了id,现在想在外面写一个绑定事件,但是报错显示没有获取到这个id, 请问各位大神这怎么解决                                 
                                             
三叔三叔2792 days ago835

reply all(6)I'll reply

  • 世界只因有你

    世界只因有你2017-06-15 09:25:29

    Did you insert the body after create?

    reply
    0
  • 仅有的幸福

    仅有的幸福2017-06-15 09:25:29

    Make sure to draw the button before getting the id of the button

    reply
    0
  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-06-15 09:25:29

    The submitButton object must exist before

    submitButton.addEventListener 🎜

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-06-15 09:25:29

    Provide several ideas:
    1. If you are using js, you need to use the createElement() method. Don’t use the wrong method.
    2. After creating the element, insert it into the dom tree
    3. Your id setting should be setAttribute()

    reply
    0
  • 巴扎黑

    巴扎黑2017-06-15 09:25:29

    I also encountered spliced ​​html when I was working. I was getting the id of a certain tag. The method I used was the document.on method to get the id of a certain tag. Personal method (for reference only^~^);

    reply
    0
  • 学习ing

    学习ing2017-06-15 09:25:29

    Why are your native JS and JQ mixed together

    reply
    0
  • Cancelreply