javascript - How to use the value of create in JS
三叔
三叔 2017-06-15 09:23:29
0
6
839
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, 请问各位大神这怎么解决                                 
                                             
三叔
三叔

reply all(6)
世界只因有你

Did you insert the body after create?

仅有的幸福

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

曾经蜡笔没有小新

The submitButton object must exist before

submitButton.addEventListener 🎜
伊谢尔伦

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()

巴扎黑

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^~^);

学习ing

Why are your native JS and JQ mixed together

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template